View Full Version : HTML page length in pixels

12-12-2002, 09:21 PM


Is it possible using Javascript to detect the length of an html page in pixels ? I need to do this as I have a javascript scroll but I need to stop the scroll when it reaches the end of the page. The only way I can think of doing it is by setting the javascript scroll end variable to the page length in pixels.

Many thanks in advance.


12-12-2002, 11:33 PM
IE has the document.body.scrollHeight (http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/scrollheight.asp) property

Not sure about everyone else...

12-12-2002, 11:57 PM
This is a guess - haven't tested it but it might work:

var docHeight = document.defaultView.getComputedStyle(body, '').getPropertyValue("height");

12-12-2002, 11:58 PM

Quiet Storm
12-13-2002, 02:10 AM
I use something like this on my iFRAME:


<DIV id="w1c1">
Blah, blah;
Blah, blah;
Blah, blah;

<script language="JavaScript">
if (document.all){
setTimeout("parent.document.all.moredivs1.innerHTML=w1c1.clientHeight+2", 1);

Then on the main page (outside the iFRAME):

<span id="moredivs1">&amp;nbsp;&amp;nbsp;&amp;nbsp;</span>

This posts the size of the DIV on the main page (outside the iFRAME)... so if I put everything inside the div (excluding this JavaScript), then it shows the size of the entire page... in pixels+2.


Hope that helps!
*this would be an IE only thing. ;)