Search code examples
javascripthtmlmobile-browser

What event tells me when a browser goes into the background?


Eg when you switch to a different app on desktop or mobile, or just view the desktop / home screen. Neither unload nor pagehide fire in this situation. visibilitychange only fires when I switch tabs on desktop.


Solution

  • Javascript: If you have an element in focus, the onblur() event will fire.

    jQuery: If you have an element in focus, the focusout() event will fire.