是否有可能检测到用户切换到不同的浏览器选项卡? [英] Is it possible to detect when a user switches to a different browser tab?
问题描述
我尝试检测用户何时从当前浏览器选项卡切换到另一个选项卡。听window.onblur在firefox中工作良好,用于检测用户何时将焦点切换到另一个窗口,但当用户切换到另一个选项卡时,似乎不会触发。但是,从另一个选项卡切换到相关标签时,似乎会激发onfocus。
I'm trying to detect when a user switches away from the current browser tab, to another tab. Listening for window.onblur works well in firefox for detecting when the user switches focus to another window, but it doesn't seem to fire when the user switches to another tab. However, it seems that onfocus is fired when switching to the tab in question, from another tab.
有没有办法检测用户何时切换到当前选项卡
Is there a way to detect when the user switches away from the current tab?
推荐答案
显然在Firefox中,如果使用 document.onBlur
而不是
window.onblur
作为事件处理程序。
Apparently in Firefox it'll work for tab switching if you use document.onBlur
instead of window.onblur
for the event handler.
这篇关于是否有可能检测到用户切换到不同的浏览器选项卡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!