Javascript 仅当选项卡未激活时触发某些内容

Javascript 仅当选项卡未激活时触发某些内容,javascript,jquery,Javascript,Jquery,我在用函数 $(window).on("blur focus", function(e) { var prevType = $(this).data("prevType"); // getting identifier to check by if (prevType != e.type) { // reduce double fire issues by checking identifier switch (e.type) { c

我在用函数

$(window).on("blur focus", function(e) {
    var prevType = $(this).data("prevType"); // getting identifier to check by
    if (prevType != e.type) {   //  reduce double fire issues by checking identifier
        switch (e.type) {
            case "blur":
                flashTitle(from + " messaged you", 500);
                break;
            case "focus":
                cancelFlashTitle();
                break;
        }
    }
    $(this).data("prevType", e.type); // reset identifier
})
我希望flash标题仅在用户不查看选项卡时触发。意味着标签现在没有焦点现在,只有当我先聚焦选项卡,然后离开(模糊)选项卡时,才会触发flash标题。


有什么想法吗?谢谢:-)

如果选项卡未聚焦,您可能希望在收到新消息时闪烁标题,因为消息就是正在发生的事件,然后取消任何聚焦闪烁。

@jackhao我的意思是,您的代码正在监视窗口事件,但它应该监视的是消息事件。消息事件应该触发整个块。我不能写代码,因为我不知道你的系统是如何工作的。