Is it possible to switch browser tab?

房东的猫 提交于 2019-12-02 18:04:38

问题


Here is my requirement,

I'm working on a enterprise application which is quite old, and it supports IE browser only. Now, there are chances that the user could open multiple tab/window from this application. I have written a custom timeout plugin for our purpose with jQuery idleTimer Plugin. When the countdown reaches 10 or less than 10, i need to switch to this tab/window to make the user aware that the page gets expired in less than 10 seconds.

So, is there a solution for this? I have tried window.focus() but does not work.


回答1:


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




回答2:


If I understand your question correctly, setting a timeout for a Javascript alert in one page then move to another tab, the alert appearing after the timeout will trigger tab switch.

setTimeout(function(){ 
    alert("Switched tabs");
}, 
5000);


来源:https://stackoverflow.com/questions/15601190/is-it-possible-to-switch-browser-tab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!