Is there a browser event for the window getting focus?

前端 未结 4 1194
走了就别回头了
走了就别回头了 2020-12-13 08:25

Is there a way that when I click on my browser, and give it focus, to run a method once? And then when the browser loses focus and then gets the focus back to again run that

4条回答
  •  暖寄归人
    2020-12-13 09:15

    $(document).ready(function() { $(window).one("focus", SomeFocusMethod); } );
    
    var SomeFocusMethod = function()
    {
        // do stuff
        $(window).one("blur", SomeBlurMethod);
    }
    
    var SomeBlurMethod = function() 
    { 
        // do stuff
        $(window).one("focus", SomeFocusMethod); 
    }
    

提交回复
热议问题