Skip to content

Instantly share code, notes, and snippets.

@bodizzle
Created July 7, 2012 19:47
Show Gist options
  • Save bodizzle/3067882 to your computer and use it in GitHub Desktop.
Save bodizzle/3067882 to your computer and use it in GitHub Desktop.
hide url bar on mobile browsers
// hide url bar
(function() {
var win = window,
doc = win.document;
// If there's a hash, or addEventListener is undefined, stop here
if ( !location.hash || !win.addEventListener ) {
//scroll to 1
window.scrollTo( 0, 1 );
var scrollTop = 1,
//reset to 0 on bodyready, if needed
bodycheck = setInterval(function(){
if( doc.body ){
clearInterval( bodycheck );
scrollTop = "scrollTop" in doc.body ? doc.body.scrollTop : 1;
win.scrollTo( 0, scrollTop === 1 ? 0 : 1 );
}
}, 15 );
if (win.addEventListener) {
win.addEventListener("load", function(){
setTimeout(function(){
//reset to hide addr bar at onload
win.scrollTo( 0, scrollTop === 1 ? 0 : 1 );
}, 0);
}, false );
}
}
})();
@buda-gotivac
Copy link

This doesn't work anymore.

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