Created
August 16, 2022 09:26
-
-
Save dhunmoon/cff05815752f1e8edbdbbd124e0b18d1 to your computer and use it in GitHub Desktop.
Get document height
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
/** | |
* Document sizes are a browser compatibility nightmare because, although all browsers expose clientHeight and s | |
* crollHeight properties, they don't all agree how the values are calculated. | |
* @return {float} Height of the page after calulation. | |
* */ | |
function getDocumentHeight(){ | |
var body = document.body, | |
html = document.documentElement; | |
var height = Math.max( body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight ); | |
return height | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment