[No000068]document.body.clientHeight 和 document.documentElement.clientHeight 的区别

时间:2023-02-15 09:59:38

document.body.clientWidth ==> BODY对象宽度

document.body.clientHeight ==> BODY对象高度

document.documentElement.clientWidth ==> 可见区域宽度

document.documentElement.clientHeight ==> 可见区域高度

注意开头<!DOCTYPE ..>的声明,没有该声明时,document.documentElement.clientHeight 始终在Chrome中为1016 px

测试代码:

<!DOCTYPE html >
<head>
<title> New Document </title>
<script language="JavaScript">
function a(){
document.getElementById("bodyheight").innerText = document.body.clientHeight;
document.getElementById("documentheight").innerText = document.documentElement.clientHeight;
}
</script>
</head> <body style= "height: 1000px;">
<p>
<a href="javascript:a()">click here</a>
<br/>
document.body.clientHeight = <span id="bodyheight"></span> px
<br/>
document.documentElement.clientHeight = <span id="documentheight"></span> px
</p>
</body>
</html>