Skip to content

Instantly share code, notes, and snippets.

@Jhony0311
Last active November 19, 2015 17:48
Show Gist options
  • Save Jhony0311/6cc9526869a034bae0ad to your computer and use it in GitHub Desktop.
Save Jhony0311/6cc9526869a034bae0ad to your computer and use it in GitHub Desktop.
Browser tab visibility control
var eventName = "visibilitychange";
if (document.webkitHidden != undefined) {
eventName = "webkitvisibilitychange";
} else if (document.mozHidden != undefined) {
eventName = "mozvisibilitychange";
} else if (document.msHidden != undefined) {
eventName = "msvisibilitychange";
} else if (document.hidden != undefined) {
} else {
}
function visibilityChanged() {
if (document.hidden || document.mozHidden || document.msHidden || document.webkitHidden) {
/* tab invisible */
} else {
/* tab visible */
}
}
document.addEventListener(eventName, visibilityChanged, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment