检测浏览器标签是否有焦点 [英] Detect If Browser Tab Has Focus

查看:31
本文介绍了检测浏览器标签是否有焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可靠的跨浏览器方式来检测选项卡是否具有焦点.

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.onblurwindow.onfocus 是一个选项吗?

Is window.onblur and window.onfocus an option for this?

推荐答案

是的,window.onfocuswindow.onblur 应该适用于您的场景:

Yes, window.onfocus and window.onblur should work for your scenario:

http://www.thefutureoftheweb.com/blog/detect-browser-window-focus

这篇关于检测浏览器标签是否有焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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