3

I am working on a web application that plays videos. I need to detect when the user switches to another application so that I can pause the video.

E.g. the browser is still open in the background but the user is now busy in Skype or some other app.

Jeandré
  • 136
  • 10

1 Answers1

1
    document.addEventListener('visibilitychange', (event) => {
    if (document.visibilityState != 'visible'){
        window.location.href = "Alert.html"
        }
    })
some-user
  • 3,888
  • 5
  • 19
  • 43
  • This might not always be reliable if the user has disabled the Visibility API in their web browser, e.g. with [Disable Page Visibility API](https://addons.mozilla.org/pl/firefox/addon/disable-page-visibility) extension for Firefox. – Piotr Henryk Dabrowski Oct 05 '22 at 10:07