Skip to content

Instantly share code, notes, and snippets.

@theskumar
Created August 24, 2012 08:45
Show Gist options
  • Select an option

  • Save theskumar/3447654 to your computer and use it in GitHub Desktop.

Select an option

Save theskumar/3447654 to your computer and use it in GitHub Desktop.
js: getDocHeight(), Get document height (cross-browser)
// Get document height (cross-browser)
//
// This function will return any document’s height. It’s been tested in IE6/7,
// FF2/3, Safari (Windows), Google Chrome and Opera 9.5. If the actual document’s
// body height is less than the viewport height then it will return the viewport
// height instead.
//
// @return {number}
function getDocHeight() {
var D = document;
return Math.max(
Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
Math.max(D.body.clientHeight, D.documentElement.clientHeight)
);
}
@davidjbradshaw

Copy link
Copy Markdown

Why do you call Math.max four times? You need the outer one.

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