Skip to content

Instantly share code, notes, and snippets.

@niallkennedy
Created June 19, 2011 18:18
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save niallkennedy/1034557 to your computer and use it in GitHub Desktop.
Save niallkennedy/1034557 to your computer and use it in GitHub Desktop.
Page Visibility API visibility test using jQuery
var isVisible = false;
function onVisible() {
isVisible = true;
jQuery.getScript("http://www.google-analytics.com/ga.js");
}
if ( document.webkitVisibilityState === undefined || document.webkitVisibilityState === "visible" ) {
onVisible();
} else {
jQuery.bind( "webkitvisibilitychange", function() {
if ( !isVisible && document.webkitVisibilityState === "visible" ) {
onVisible();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment