Search code examples
javascriptwindowonblur

window.onblur not working


I can't seem to get window.onblur to work properly.

window.onblur = console.log('blur');

When the listener is applied to the window, it just runs when the page is loaded, but not when the window looses focus.


Solution

  • window.onblur = function() { console.log('blur'); }