I wish to determine using jquery or javascript that is the user has switched tab standing on the same browser?
I.e. if the user is currently standing on browser say mozilla-firefox tab no.1 , now he has opened another tab say tab no.2 , at that point a popup should appear , with the message "tab changed"
I believe you can use the window.onblur
event which will fire when the current page loses focus.
window.onblur = function() {
// Your action here
};
In jQuery, you write it this way
$(window).blur(function() {
// Your action here
});
Without jQuery
window.onblur = function () {
// do some stuff after tab was changed e.g.
alert('You switched the tab');
}
with jQuery:
$('window').blur(function () {
// do some stuff after tab was changed e.g.
alert('You switched the tab');
});
Of course displaying alert is not best thing to do, because it focus current tab again :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With