admin管理员组文章数量:1386773
I'm writing a webapp that performs an action every minute or so which (very briefly) hangs the browser. I'd like to pause this action when the tab displaying the webapp is not shown, to minimize the annoyance. Is there any way to do this using Javascript, under the latest version of Firefox?
Edit: to clarify, I'm asking about how to determine the visibility of the tab that some JS code is running in - not how to pause/resume the action which hangs the browser.
I'm writing a webapp that performs an action every minute or so which (very briefly) hangs the browser. I'd like to pause this action when the tab displaying the webapp is not shown, to minimize the annoyance. Is there any way to do this using Javascript, under the latest version of Firefox?
Edit: to clarify, I'm asking about how to determine the visibility of the tab that some JS code is running in - not how to pause/resume the action which hangs the browser.
Share Improve this question edited Dec 3, 2009 at 16:51 Matt Ball asked Dec 3, 2009 at 16:39 Matt BallMatt Ball 360k102 gold badges653 silver badges720 bronze badges3 Answers
Reset to default 7var isFocused = true;
window.onblur=function(){
if(isFocused==true){
isFocused=false;
}
}
window.onfocus = function(){
isFocused = true;
}
Now, that action you perform, every minute or two, do it only when isFocused is true. That is when the tab of your page/webapp is focused.
Not tested, but how about this:
window.onblur() = function () {
... pause your script here
}
I don't know if Firefox handles the window blur in tabs as separate windows.
I believe you will need to make do with the window.onblur event, because accessing the browser window from a script in a webpage is forbidden for security reasons (only allowed for privileged scripts).
What you want to do (access the browser window from within a child window or a webpage) is described in Mozilla Developer Center, but it does mention there that only a privileged script can do it, and you'll probably get a "Premission denied" error when you try.
本文标签: javascriptDetecting tab visibility in FirefoxStack Overflow
版权声明:本文标题:javascript - Detecting tab visibility in Firefox - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744491785a2608777.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论