jQuery - window focus, blur events not triggering - works in Firefox and Chrome

早过忘川 提交于 2019-12-04 09:49:32

I don't think google chat uses the window to check focus. It uses the textbox of the user chatting to you. As soon as the textbox receives focus " Says..." stops looping.

You might want to check for mouse movements to see if the window has focus. Other than that, I am still trying to figure out how to check the window for focus when trying to keep a page live.

This bit of jquery will work in IE and all the good browsers (chrome, ff etc). The key is document focusin\focusout for IE support.

$(function(){
    $(window).bind('blur', function(){
        console.debug('window blur');
    });

    $(window).bind('focus', function(){
        console.debug('window focus');
    });
    // IE EVENTS
    $(document).bind('focusout', function(){
        alert('document focusout');
    });

    $(document).bind('focusin', function(){
        alert('document focusin');
    });
});

What happens if you attempt to bind to the document element?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!