Some browsers report the window height incorrectly differently - particularly mobile browsers, which have a different viewport concept. I sometimes use a function to check several different values, returning whichever is the greatest. For example
function documentHeight() {
return Math.max(
window.innerHeight,
document.body.offsetHeight,
document.documentElement.clientHeight
);
}
Edit: I just looked at how jQuery does it and it does indeed use Math.max and a series of properties - however the list it checks is slightly different to those in my example above, and since I usually trust the jQuery team to be better at this stuff than I am; here is the non-jQuery jQuery solution (if that makes any sense):
function documentHeight() {
return Math.max(
document.documentElement.clientHeight,
document.body.scrollHeight,
document.documentElement.scrollHeight,
document.body.offsetHeight,
document.documentElement.offsetHeight
);
}