简体   繁体   English

Javascript - 如何使浏览器切换标签?

[英]Javascript - How to make a browser switch tabs?

In my code a timed event launches a ModalDialog. 在我的代码中,定时事件启动ModalDialog。 If the user switches tabs before the event the tab blinks but that is it. 如果用户在事件之前切换选项卡,则选项卡会闪烁,但就是这样。

Is there a way to make the browser switch to the tab the dialog is on? 有没有办法让浏览器切换到对话框所在的选项卡?

Thank you 谢谢

Cheers for all your advice. 为您的所有建议干杯。 I should of said before but code will only be run through IE and the users are not allowed to alter any settings. 我之前应该说,但代码只能通过IE运行,并且不允许用户更改任何设置。

There isn't a cross-browser way do focus a tab/window that's 100% reliable, especially in newer browsers. 没有跨浏览器的方式可以集中100%可靠的选项卡/窗口,尤其是在较新的浏览器中。 This would be an advertisers dream...so it's actively blocked in most newer browsers. 这将是广告商梦寐以求的......所以它在大多数新版浏览器中被主动阻止

As a user, I'm glad it's difficult in most cases, impossible in others to do this. 作为用户,我很高兴在大多数情况下很难,其他人不可能这样做。

There is no reliable way to do that. 没有可靠的方法可以做到这一点。 The Internet Explorers are the most cooperative about raising windows (which is what switching tabs amounts to), while Safari pretty much ignores all such requests. Internet Explorers是关于提升窗口最合作的(这是切换选项卡的含义),而Safari几乎忽略了所有这些请求。 Firefox can be configured (by its user, not by your code) to allow windows to grab focus, but it's rare for anybody to do that. 可以(通过其用户,而不是您的代码)配置Firefox以允许窗口获取焦点,但任何人都很少这样做。

You can have your code call window.focus() but don't rely on it to work. 你可以让你的代码调用window.focus()但不要依赖它来工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM