Cross-browser: detect blur event on window

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

    I tried using the addEventListener DOM function

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

    I got it to work after the first blur. but it didnt work when I didnt have the click function attached to it. There might be some kind of refresh that happens when a click function is interpreted

提交回复
热议问题