Skip to content

Instantly share code, notes, and snippets.

@kara-ryli
Created November 6, 2010 06:14
Show Gist options
  • Save kara-ryli/665231 to your computer and use it in GitHub Desktop.
Save kara-ryli/665231 to your computer and use it in GitHub Desktop.
How to set the <body> tag's height to the full window height and still get it right on the iPhone.
window.onload = function () {
var s = document.body.style;
s.height = window.screen.availHeight + 'px';
setTimeout(function () {
window.scrollTo(0, 0);
s.height = window.innerHeight + 'px';
}, 50);
};
@kara-ryli
Copy link
Author

You have no idea how long I had to poke on this to get it right. The iPhone lies about a lot of things; window.innerHeight, window.scrollY are the fun ones.

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