Javascript: How to create event listener on Window.Blur() event?
The blur event fires when an element has lost focus. The event does not bubble, but the related focusout event that follows does bubble. The opposite of blur is the focus event, which fires when the element has received focus.
blur() method removes keyboard focus from the current element.
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');
});
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With