Detect browser tab changes using javascript

There is some way to detect javascript usage that the user has switched to another tab in the same browser window.

Also, is there a way to detect that the user has switched to a different window than the browser?

Thank you

+6
source share
3 answers

window.onblur trap.

It rises whenever the current window (or tab) loses focus.

+2
source

Most likely, there are no javascript standards for this. Some browsers may support it, but usually there is only the window.onblur event to find out that the user has left the current window.

+1
source

For this, the page visibility API was developed. Read at this url:

https://developer.mozilla.org/en-US/docs/Web/Guide/User_experience/Using_the_Page_Visibility_API

+1
source

All Articles