检测浏览器标签是否有焦点 [英] Detect If Browser Tab Has Focus
问题描述
是否有可靠的跨浏览器方式来检测选项卡是否具有焦点.
Is there a reliable cross-browser way to detect that a tab has focus.
这个场景是我们有一个应用程序定期轮询股票价格,如果页面没有焦点,我们可以停止轮询并为每个人节省交通噪音,特别是当人们喜欢打开几个不同的标签时投资组合.
The scenario is that we have an application that polls regularly for stock prices, and if the page doesn't have focus we could stop the polling and save everyone the traffic noise, especially as people are fans of opening several tabs with different portfolios.
window.onblur
和 window.onfocus
是一个选项吗?
Is window.onblur
and window.onfocus
an option for this?
推荐答案
是的,window.onfocus
和 window.onblur
应该适用于您的场景:
Yes, window.onfocus
and window.onblur
should work for your scenario:
http://www.thefutureoftheweb.com/blog/detect-browser-window-focus一个>
这篇关于检测浏览器标签是否有焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!