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