Some browsers report window heights incorrectly in different ways - especially mobile browsers that have a different viewport concept. Sometimes I use a function to check for several different values, returning whichever is the most. for instance
function documentHeight() {
return Math.max(
window.innerHeight,
document.body.offsetHeight,
document.documentElement.clientHeight
);
}
Edit: I just looked at how jQuery works, and it really uses Math.max and a number of properties, however the list that it checks is slightly different from the ones shown in my example above, and since I usually trust the jQuery command to be better at this material than me; this is a jQuery solution other than jQuery (if that makes sense):
function documentHeight() {
return Math.max(
document.documentElement.clientHeight,
document.body.scrollHeight,
document.documentElement.scrollHeight,
document.body.offsetHeight,
document.documentElement.offsetHeight
);
}
source
share