document.body.clientHeight not returning correct values (in below code return 0 onload and 20 onresize )
Untitled
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 )
.clientHeight
gives us a Integer value only. But here scale-type of size is missing that's why it is not working correctly just add + "px"
just after document.body.clientHeight
.
<script>
function height1() {
document.getElementById("viewheight").innerHTML = document.body.clientHeight + "px";
}
</script>