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".
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.