I'm trying to get the total height of a page using JavaScript so I can check if the page is long enough to display something, however in my testing I am unable to get the total height of a page.
I've looked around on the Internet but things like this don't seem to be well documented, as all I can find is scrollHeight
, which, as I might mention, doesn't work.
Any way to use JavaScript to find it?
scrollHeight will give you the height of the page including stuff you need to scroll to see. offsetHeight will give you the height of the visible window content area. and offsetHeight does not contain borders, margins and padding.
To get the height of a document, we can get the max of the scrollHeight , offsetHeight , or clientHeight properties. The document can be stored in the document. body or document. documentElement properties depending on the browser used.
php if(! $_REQUEST['pageHeight']){ echo " <script src="jquery url here"/> <script> function getPageHeight(){ return (window). height();//or some other way } $(document). ready(function(){ var url = location.
$(document). height() returns an unit-less pixel value of the height of the document being rendered. However, if the actual document's body height is less than the viewport height then it will return the viewport height instead.
Without a framework:
var _docHeight = (document.height !== undefined) ? document.height : document.body.offsetHeight; var _docWidth = (document.width !== undefined) ? document.width : document.body.offsetWidth;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With