I would like to run a function whenever a browser tab is active/selected.
How do I do it using JavaScript/jQuery?
I would like to run a function whenever a browser tab is active/selected.
How do I do it using JavaScript/jQuery?
Perhaps you can use the Page Visibility API ? The specification is at http://www.w3.org/TR/2011/WD-page-visibility-20110602/
"This specification defines a means for site developers to programmatically determine the current visibility state of the page in order to develop power and CPU efficient web applications."
There is also a handy wrapper library for it - Visibility.js at https://github.com/ai/visibility.js
Visibility.onVisible(function () {
// do something
});