Event for browser tab hidden/shown?(隐藏/显示浏览器选项卡的事件?)
问题描述
当浏览器标签失去/获得焦点时是否有任何 DOM 事件?我知道在 window
上有 blur
和 focus
事件,但是当整个浏览器窗口失去焦点时它们也会触发.然后浏览器可能对用户仍然可见.当然,这样的事件将是特定于浏览器的,但没关系.
Is there any DOM event for when the browser tab loses/gains focus? I know there are the blur
and focus
events on window
, but they also fire when the browser window as a whole loses focus. The browser might then be still visible to the user. Of course such an event would be browser specific, but that's ok.
我想要这个的原因是因为我运行的动画可能会消耗相当多的 CPU 时间.当浏览器选项卡不可见时,没有理由继续制作动画.现在我知道现代浏览器会降低背景选项卡的计时器分辨率,但我实际上可以暂停动画,这样就不会消耗任何 CPU 时间.
The reason why I want this is because I run animations that might consume quite some CPU time. When the browser tab is not visible there is no reason to continue animating. Now I know that modern browsers reduce the timer resolution of background tabs, but I could actually pause the animation, so that no CPU time whatsoever is consumed.
如果您想知道,这就是我要写的内容:http://panzi.github.com/Browser-Ponies/
In case you are wondering, this is what I'm writing: http://panzi.github.com/Browser-Ponies/
推荐答案
至少 Google Chrome 支持 webkitvisibilitychange
事件和 document.webkitHidden
属性.请参阅可见性 API.但它似乎只在显示的选项卡更改时触发,而不是在整个窗口最小化时触发.Internet Explorer 似乎还有一个 visibilitychange
事件,但是 文档 没有说明任何内容.
At least Google Chrome supports a webkitvisibilitychange
event and a document.webkitHidden
property. See the visibility API. But it seems only to fire when the shown tab changes, not when the whole window is minimized. There also seems to be a visibilitychange
event for Internet Explorer, but the documentation doesn't say anything about it.
这篇关于隐藏/显示浏览器选项卡的事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:隐藏/显示浏览器选项卡的事件?


基础教程推荐
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01