I looked at this:
How to find out if the browser / tab is active
and
Is there a reliable way to determine if a tab or browser window is inactive or not in focus?
The first link provides a solution for modern browsers, but does not work in IE7 / 8. Both of these questions are pretty old. Is there a solution to the problem of determining whether a visitor views his open tab or not?
Pretty much everything I 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;
});
setInterval(function () {
console.log(window.isActive ? 'active' : 'inactive');
}, 1000);
source
share