检测浏览器选项卡是否具有焦点 [英] Detect If Browser Tab Has Focus

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

问题描述

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

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 这是一个选项吗?

推荐答案

是的, 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屋!

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