Created
April 7, 2013 17:49
-
-
Save anonymous/5331564 to your computer and use it in GitHub Desktop.
iPhone Mobile Safari window height without address bar or button bar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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