简体   繁体   English

打开用户的浏览器,或者如果网站已经打开,则切换到相应的选项卡

[英]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.

相关问题 在制表符开关上或在离开UIViewController的焦点时运行方法 - Run a method on tab switch or when leaving a UIViewController's focus 切换回标签视图 - Switch Back to Tab View 为“超本地”应用程序获取用户位置(也处于被杀死状态)的适当方法 - Appropriate way to get user's location(also in killed state) for an “hyperlocal” app 应用程序可以打开浏览器,让用户登录并接收文件吗? - Can app open browser, get user to login and receive file? 使用FBSDKMessenger打开特定用户的Facebook Messenger - Open particular user's facebook messenger with FBSDKMessenger 当用户已经登录另一个选项卡时,在选择选项卡时导航另一个屏幕-iOS - Navigating another screen when tabbar selected when user already logged in another tab-iOS 用户已经登录后如何处理选项卡视图控制器中的登录窗口 - how to handle login window in tab view controller when user is already logged in 一些AppStore浏览器应用程序如何实现“打开新标签”菜单,加载进度等功能? - How do some AppStore browser apps implement features such as “Open in new tab” menu, loading progress, etc? setCollectionBehavior对已打开的窗口不起作用 - setCollectionBehavior not taking affect on already opened window 如果应用程序尚未打开,则“打开...”问题 - “Open with…” issue if app is not already open
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM