Using JQuery to bind “focus” and “blur” functions for “window”, doesn't work in IE

前端 未结 3 1265
遥遥无期
遥遥无期 2020-11-29 04:47

I need to use JQuery like the follwoing:

var focusFlag = 1;
jQuery(window).bind(\"focus\", function(event)
{
focusFlag = 1;
});

jQuery(window).bind(\"blur\"         


        
3条回答
  •  失恋的感觉
    2020-11-29 05:25

    Just to have the right answer here:

    $(function() {
        $(window).focus(function() {
            console.log('Focus');
        });
    
        $(window).blur(function() {
            console.log('Blur');
        });
    });
    

    Note that in FF and IE the "Focus" event fires on ~document load, while in Chrome it only fires if the window had lost focus before and now it has regained it.

提交回复
热议问题