Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Total height of the page

Tags:

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?

like image 945
Brandon Wang Avatar asked Jul 06 '09 16:07

Brandon Wang


People also ask

How do you find the total height of a page?

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.

How do you find the height of a document?

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.

How can I get page height in PHP?

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.

What is $( document height ()?

$(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.


1 Answers

Without a framework:

var _docHeight = (document.height !== undefined) ? document.height : document.body.offsetHeight; var _docWidth = (document.width !== undefined) ? document.width : document.body.offsetWidth; 
like image 104
Andreas Grech Avatar answered Oct 18 '22 22:10

Andreas Grech