检测Firefox中的选项卡可见性 [英] Detecting tab visibility in Firefox
问题描述
编辑:澄清,我在问以确定一些JS代码运行的标签的可见性 - 而不是如何暂停/恢复挂起浏览器的动作。
var isFocused = true;
$ b $ window.onblur = function(){
if(isFocused == true){
isFocused = false;
window.onfocus = function(){
isFocused = true;
$ / code>
现在,您每分钟执行一次该操作, isFocused是真的。这就是当你的页面/ web应用程序的选项卡焦点。
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.
var 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.
这篇关于检测Firefox中的选项卡可见性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!