get the height of the rendered HTML page

I am trying to get the height of the rendered HTML page(the final graphical representation shown in the browser). Is this even posible? because i get "undefined" at the output.

Here is the code:
<html>
<script type="text/javascript">
function getDim()
{
document.write(document.clientHeight)
}
</script>
<body bgcolor="#66CCFF">
<table id=source>
<tr><td height=20>
<h3>Frame A</h3>
</td></tr>
<form>
<input type="button" onclick="getDim()" value="ShowMe">
</form>
</body>
</html>
LVL 1
xtremecrisAsked:
Who is Participating?
 
BatalfCommented:
If you use a strict doctype, then you can use document.body.clientHeight

example:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<title>Test</title>
<head>
<script type="text/javascript">
function getDim()
{
    alert(document.body.clientHeight)
}
</script>
<body bgcolor="#66CCFF">
<table id=source>
<tr><td height=20>
<h3>Frame A</h3>
</td></tr>
</table>
<form>
<input type="button" onclick="getDim()" value="ShowMe">
</form>

</body>
</html>

If you're not using a doctype(Which you absolute should), you could put an outer DIV surrounding your HTML and measure the height of that div.

Example:

<html>
<title>Test</title>
<head>
<script type="text/javascript">
function getDim()
{
    alert(document.getElementById('content').offsetHeight)
}
</script>
<body bgcolor="#66CCFF">
<div id="content">
<table id=source>
<tr><td height=20>
<h3>Frame A</h3>
</td></tr>
</table>
<form>
<input type="button" onclick="getDim()" value="ShowMe">
</form>
</div>
</body>
</html>
0
 
ZvonkoSystems architectCommented:
Check this:

<html>
<script type="text/javascript">
function getDim(){
  alert(document.body.clientHeight)
}
</script>
<body bgcolor="#66CCFF">
<table id=source>
<tr><td height=20>
<h3>Frame A</h3>
</td></tr>
</table>
<form>
<input type="button" onclick="getDim()" value="ShowMe">
</form>
</body>
</html>

0
 
xtremecrisAuthor Commented:
Excelent Batalf, 100x. :)
0
 
BatalfCommented:
Glad I could help!

Batalf
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.