Javascript - How to make a browser switch tabs?

前端 未结 2 1318
悲&欢浪女
悲&欢浪女 2021-01-15 16:02

In my code a timed event launches a 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

相关标签:
2条回答
  • 2021-01-15 16:45

    There isn't a cross-browser way do focus a tab/window that's 100% reliable, especially in newer browsers. 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.

    0 讨论(0)
  • 2021-01-15 16:58

    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. 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.

    You can have your code call window.focus() but don't rely on it to work.

    0 讨论(0)
提交回复
热议问题