Skip to content

Instantly share code, notes, and snippets.

Created April 7, 2013 17:49
Show Gist options
  • Save anonymous/5331564 to your computer and use it in GitHub Desktop.
Save anonymous/5331564 to your computer and use it in GitHub Desktop.
iPhone Mobile Safari window height without address bar or button bar
var isiPhone = (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i));
var getWindowHeight = function(){
return isiPhone ? window.screen.availHeight - (window.navigator.standalone ? 0 : 44) : $(window).height();
}
//Lose the address bar
$(window).load(function(){
// http://stackoverflow.com/questions/2526315/strange-jquery-window-load-behavior-in-safari
// Checking for an offset forces safari for finish loading/layout out the content, it blocks javascript until the return completes. You can use it like this:
var block = document.body.offsetWidth;
// Set a timeout...
if(isiPhone){
setTimeout(function(){
window.scrollTo(0, 1);
}, 0);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment