检测Firefox中的选项卡可见性 [英] Detecting tab visibility in Firefox

查看:143
本文介绍了检测Firefox中的选项卡可见性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个web应用程序,每分钟执行一个动作(非常短暂地)挂起浏览器。我想在显示webapp的标签不显示的时候暂停这个动作,以尽量减少烦恼。有没有什么办法可以在Firefox的最新版本下使用Javascript做到这一点?



编辑:澄清,我在问以确定一些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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆