打开用户的浏览器,或者如果网站已打开,则切换到相应的选项卡
在我的 Objective-C 应用程序中,我使用此代码在用户浏览器中打开一个网站:
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://blah.com/"]];
效果很好。不过,有一个小问题;如果用户已经在其网络浏览器中打开“blah.com”,则调用此命令会不必要地创建一个新选项卡。
在这种情况下,如果直接切换到现有选项卡,用户体验会更好。
有办法做到这一点吗?请注意,如果选项卡位于“blah.com”的子页面(例如“blah.com/some/page.html”)上,我还想切换到现有选项卡。
In my Objective-C app, I use this code to open a website in the user's browser:
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://blah.com/"]];
This works fine. However, there is one small problem; if the user already has opened "blah.com" in his webbrowser, calling this unncessarily creates a new tab.
It would be better user experience if it simply switched to the existing tab in those cases.
Is there a way to do this? Note that I would also want to switch to the existing tab if the tab is on a subpage of "blah.com", like "blah.com/some/page.html".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能使用
-[NSWorkspace openURL:]
来做到这一点。如果您知道用户正在使用 Chrome 或 Safari,您可以通过运行一些 AppleScript 来做到这一点。You can't do it with
-[NSWorkspace openURL:]
. If you know that the user is using Chrome or Safari, you can do it by running some AppleScript.