简体   繁体   中英

Javascript: How to create event listener on Window.Blur () event?

Javascript:如何在Window.Blur()事件上创建事件监听器?

window.onblur = function() {
   //say goodbye
};

According to quirksmode onfocus and onblur are available on the window in most browsers.

It's better to use addEventListener instead of a property, this way you can set multiple handlers and nobody (including yourself) will accidentally disable your handler by overwriting the onblur property.

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

Try:

window.onBlur = function(e) {
    // Code here.
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM