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
window.onblur trap.
window.onblur
It rises whenever the current window (or tab) loses focus.
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.
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