Cross-browser: detect blur event on window

后端 未结 6 2331
挽巷
挽巷 2021-02-08 03:24

I just read, I think all the thread that deals with this subject, and I can\'t find a real solution to my problem. I need to detect when the browser window loses its focus, i.e.

6条回答
  •  伪装坚强ぢ
    2021-02-08 03:42

    You can use jQuery's blur method on window, like so:

    $(document).ready(function() {
      $(window).blur(function() {
        // Put your blur logic here
        alert("blur!");
      });
    });
    

    This works in Firefox, IE, Chrome and Opera.

提交回复
热议问题