Created
August 24, 2012 08:45
-
-
Save theskumar/3447654 to your computer and use it in GitHub Desktop.
js: getDocHeight(), Get document height (cross-browser)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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) | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why do you call Math.max four times? You need the outer one.