Cross-browser: detect blur event on window

后端 未结 6 2336
挽巷
挽巷 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:57

    I tried both:

    document.addEventListener('blur', function(){console.log('blur')});
    

    and

    window.addEventListener('blur', function(){console.log('blur')});
    

    and they both worked in my version of FF (33.1).

    Here's the jsfiddle: http://jsfiddle.net/hzdd06eh/

    Click inside the "run" window and then click outside it to trigger the effect.

提交回复
热议问题