admin管理员组文章数量:1289773
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.
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.
In case you are wondering, this is what I'm writing: /
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.
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.
In case you are wondering, this is what I'm writing: http://panzi.github./Browser-Ponies/
Share Improve this question edited Nov 7, 2015 at 16:11 Anders 8,58810 gold badges59 silver badges99 bronze badges asked Sep 20, 2011 at 2:07 panzipanzi 7,7015 gold badges46 silver badges54 bronze badges 1- So are you asking how to tell when a tab stops being visible, or stops having focus? – nnnnnn Commented Sep 20, 2011 at 2:23
3 Answers
Reset to default 5At 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.
The closest thing I believe you'll find is the top answer here:
Is there a way track the focus on tab with Javascript?
Now they have exactly what was needed: https://developer.mozilla/en-US/docs/Web/Guide/User_experience/Using_the_Page_Visibility_API
本文标签: javascriptEvent for browser tab hiddenshownStack Overflow
版权声明:本文标题:javascript - Event for browser tab hiddenshown? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741481750a2381211.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论