admin管理员组文章数量:1291144
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);
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);
Share
Improve this question
edited May 23, 2017 at 12:22
CommunityBot
11 silver badge
asked Aug 8, 2011 at 8:05
ComputerUserComputerUser
4,88816 gold badges60 silver badges72 bronze badges
2 Answers
Reset to default 7After much Googling... then some more... then some more... 4 hours or so later I finally found this link hidden in the depths of the internet. The ments suggest a small bug exists but it is fine for what I need it for.
http://www.thefutureoftheweb./blog/detect-browser-window-focus
var isActive = true;
function onBlur() {
isActive = false;
};
function onFocus(){
isActive = true;
};
if (/*@cc_on!@*/false) { // check for Internet Explorer
document.onfocusin = onFocus;
document.onfocusout = onBlur;
} else {
window.onfocus = onFocus;
window.onblur = onBlur;
}
Slightly different but this was marked as the answer suggesting it worked and it is a delay that's needed. Not very elegant but if it works.
本文标签: javascriptDetermine if browser tab is activeIEStack Overflow
版权声明:本文标题:javascript - Determine if browser tab is active? - IE? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741525464a2383438.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论