...

View Full Version : Determining the document height



bugman
02-24-2007, 12:46 PM
Hi. I've been running around the web, including a search here, but haven't hit upon a solution that works. I'm trying to determine the document height of a web page. The following code produces a 0 (zero) onload, and again when the button is pressed. Right now, I'm working with Firefox 2 on Ubuntu Edgy. I'll worry about IE compatability later. Thanks



<html>
<head>
<title>test</title>

<style type="text/css">
#container
{
position: absolute;
top: 0px;
left: 0px;
width: 500px;
height: 2000px;
border: 1px solid black;
}
</style>

<script type="text/javascript">

var _params=new Array();

function getParams()
{
var _docHeight = (typeof document.height != "undefined") ? document.height : document.body.scrollHeight;
var _docWidth = (document.width != "undefined") ? document.width : document.body.offsetWidth;
alert(_docHeight);
} // end function getParams()

</script>
</head>
<!-- onLoad="_params=getParams();" -->
<body onLoad="_params=getParams();">
<div id="container">
<form id="hi" action="#" method="post">
<input type="submit" onClick=('getParams();') value="click me" />
</form>
</div>
</body>
</html>

BarrMan
02-24-2007, 01:49 PM
This works in IE, not sure about firefox but give it a shot.

document.body.clientHeight

MikeFoster
02-24-2007, 04:22 PM
Have a look at this: xDocSize (http://cross-browser.com/x/lib/view.php?sym=xDocSize).

bugman
02-25-2007, 08:23 PM
Thanks for the input from both of you. xDocSize() led me to the correct property (document.body.scrollHeight). Now if I could find a good cheat sheet for this stuff....



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum