[英]Open user's browser, or switch to the appropriate tab if the website is already opened
In my Objective-C app, I use this code to open a website in the user's browser: 在我的Objective-C应用程序中,我使用此代码在用户的浏览器中打开一个网站:
[[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.
如果用户已经在他的webbrowser中打开了“blah.com”,则不必要地调用它会创建一个新选项卡。
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".
请注意,如果选项卡位于“blah.com”的子页面上,我还想切换到现有选项卡,例如“blah.com/some/page.html”。
You can't do it with -[NSWorkspace openURL:]
. 您无法使用
-[NSWorkspace openURL:]
。 If you know that the user is using Chrome or Safari, you can do it by running some AppleScript. 如果您知道用户正在使用Chrome或Safari,则可以通过运行AppleScript来实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.