Skip to content

Instantly share code, notes, and snippets.

@adamcoulombe
Forked from anonymous/iPhoneWindowHeight.js
Last active December 15, 2015 22:18
Show Gist options
  • Save adamcoulombe/5331569 to your computer and use it in GitHub Desktop.
Save adamcoulombe/5331569 to your computer and use it in GitHub Desktop.
var isiPhone = (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i));
var getWindowHeight = function(){
// this was the most reliable way I could find of getting the actual viewport height without the status, address or button bar.
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