Skip to content

Instantly share code, notes, and snippets.

@cyakimov
Forked from niallkennedy/visibility.js
Created June 20, 2011 16:01
Show Gist options
  • Save cyakimov/1035883 to your computer and use it in GitHub Desktop.
Save cyakimov/1035883 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