使用jQuery检测窗口未聚焦或选项卡开关 [英] Detect window not focused or tab switch with jquery
本文介绍了使用jQuery检测窗口未聚焦或选项卡开关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检测用户何时收到新的带有"x个新消息"的聊天消息时切换标签以更改标题区域
我尝试过:
var isActive;
window.onfocus = function(){ isActive = true; };
window.onblur = function(){ isActive = false; };
这对我不起作用.另外,它不必一定是选项卡,我想确保它检测到特定的窗口没有被聚焦,然后做点什么".
非常感谢所有帮助!
解决方案
使用jQuery或Mootools进行检测
$(window).blur(function(e) {
// Do Blur Actions Here
});
$(window).focus(function(e) {
// Do Focus Actions Here
});
源:用户切换浏览器标签时的事件 >
I want to detect when the user switches a tab in order to change the title area when they receive a new chat message with "x new messages"
I tried:
var isActive;
window.onfocus = function(){ isActive = true; };
window.onblur = function(){ isActive = false; };
This does not work for me. Also, it doesn't have to be tabs, I want to make sure it detects that the specific window is not focused then 'do something'.
All help is much appreciated!
解决方案
USE jQuery or Mootools for detecting
$(window).blur(function(e) {
// Do Blur Actions Here
});
$(window).focus(function(e) {
// Do Focus Actions Here
});
source: Event for when user switches browser tabs
这篇关于使用jQuery检测窗口未聚焦或选项卡开关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文