document.body.clientHeight not returning correct values (in below code return 0 onload and 20 onresize )
<html>
<head>
<title>Untitled</title>
<script type="text/javascript" >
function height1()
{
document.getElementById("viewheight").innerHTML = document.body.clientHeight;
}
</script>
</head>
<body onload="height1();" onresize="height1();">
<span id="viewheight"></span>
</body>
</html>
Any Comments..... plz help!
Try it with document.getElementById("viewheight").innerHTML = window.innerHeight;
The behaviour of your script is totally correct. At the start the height of your body is really zero (body height is the height of the document). Because there's nothing shown, the height results with zero. After resizing your printed "0" spans over 20px, so the result will stay at 20px.
If you want to get the maximum height of the window or the body you could use Math.max( window.innerHeight, document.body.clientHeight )
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