
网页可见区域宽: documentbodyclientWidth
网页可见区域高: documentbodyclientHeight
网页可见区域宽: documentbodyoffsetWidth (包括边线的宽)
网页可见区域高: documentbodyoffsetHeight (包括边线的高)
网页正文全文宽: documentbodyscrollWidth
网页正文全文高: documentbodyscrollHeight
网页被卷去的高: documentbodyscrollTop
网页被卷去的左: documentbodyscrollLeft
网页正文部分上: windowscreenTop
网页正文部分左: windowscreenLeft
屏幕分辨率的高: windowscreenheight
屏幕分辨率的宽: windowscreenwidth
屏幕可用工作区高度: windowscreenavailHeight
屏幕可用工作区宽度: windowscreenavailWidth
--------------这种问题网上一搜一大把,关键是要理解其中JS获取的原理----------
<html>
<head>
</head>
<body style="height:400px">
<div id="div1">12312</div>
<script type="text/javascript">
documentgetElementById("div1")styleheight=documentbodystyleheight;
alert(documentgetElementById("div1")styleheight);
//如果body,没有设置样式,这个高度就为空
documentgetElementById("div1")styleheight=documentbodyclientHeight
alert(documentgetElementById("div1")styleheight);
//如果设置了样式,offsetHeight就等于样式的height否则等于clientHeight
documentgetElementById("div1")styleheight=documentbodyoffsetHeight
alert(documentgetElementById("div1")styleheight);
</script>
</body>
</html>
用clientHeight或offsetHeight。
对于没有具体设置高度的元素,不能直接用height获取高度。
clientHeight表示内容可见区域高度;offsetHeight不同浏览器数值不尽相同,除了clientHeight的高度外还包括边框等的高度。
以上就是关于如何通过JS获取指定页面的高度全部的内容,包括:如何通过JS获取指定页面的高度、JS获取HTML页面的BODY的高度、怎么用js获取到外部样式表写的高度为auto的div的真实高度呢等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)