Skip to content

Instantly share code, notes, and snippets.

@iainmcampbell
Created February 2, 2015 21:55
Show Gist options
  • Save iainmcampbell/4317113e64996352db1e to your computer and use it in GitHub Desktop.
Save iainmcampbell/4317113e64996352db1e to your computer and use it in GitHub Desktop.
Page Visibility API
var hidden
, visibilityChange
// browser prefixes
if (typeof document.hidden !== "undefined") { // Opera 12.10 and Firefox 18 and later support
hidden = "hidden"
visibilityChange = "visibilitychange"
} else if (typeof document.mozHidden !== "undefined") {
hidden = "mozHidden"
visibilityChange = "mozvisibilitychange"
} else if (typeof document.msHidden !== "undefined") {
hidden = "msHidden"
visibilityChange = "msvisibilitychange"
} else if (typeof document.webkitHidden !== "undefined") {
hidden = "webkitHidden"
visibilityChange = "webkitvisibilitychange"
}
function handleVisibilityChange() {
if (document[hidden]) {
} else {
}
}
if (typeof document.addEventListener === "undefined" || typeof document[hidden] === "undefined"){
document.addEventListener(visibilityChange, handleVisibilityChange, false)
}
}
@iainmcampbell
Copy link
Author

mdn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment