I have looked at this:
How to tell if browser/tab is active
and:
Is there a reliable way to determine if a browser tab or window is inactive or not in focus?
The first link provides a solution for modern browsers but doesn't work in IE7/8. Both of these questions are fairly old. Is there a solution to the problem of determining whether a visitor is viewing their open tab or not?
Pretty much everything I have tried works fine in Chrome. But IE7 just fails.
I just want to set a global variable that says whether the page is being viewed.
i.e.
var isActive = true;
$(window).focus(function() {
isActive = true;
});
$(window).blur(function() {
isActive = false;
});
// test
setInterval(function () {
console.log(window.isActive ? 'active' : 'inactive');
}, 1000);