Skip to content

Instantly share code, notes, and snippets.

@abha57
Created January 25, 2021 18:39
Show Gist options
  • Select an option

  • Save abha57/c034e95fa82a389223c99b6df26f5d21 to your computer and use it in GitHub Desktop.

Select an option

Save abha57/c034e95fa82a389223c99b6df26f5d21 to your computer and use it in GitHub Desktop.
document.visibilityState
How to check if a Browser Tab is active or not? 🔥
0. Stop video if the user changes the browser tab
1. Reduce Polling Rate of Data from API
2. Stop music if the user moves out
document.visibilityState
// 'visible'
document.addEventListener("visibilitychange", function() {
console.log( document.visibilityState );
// Modify behavior...
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment