js获取屏幕高度和宽度

来源:互联网 发布:java输入布尔类型 编辑:程序博客网 时间:2024/05/22 00:30

网页可见区域宽: document.body.clientWidth
网页可见区域高: document.body.clientHeight
网页可见区域宽: document.body.offsetWidth (包括边线的宽)
网页可见区域高: document.body.offsetHeight (包括边线的高)
网页正文全文宽: document.body.scrollWidth
网页正文全文高: document.body.scrollHeight
网页被卷去的高: document.body.scrollTop
网页被卷去的左: document.body.scrollLeft
网页正文部分上: window.screenTop
网页正文部分左: window.screenLeft
屏幕分辨率的高: window.screen.height
屏幕分辨率的宽: window.screen.width
屏幕可用工作区高度: window.screen.availHeight
屏幕可用工作区宽度: window.screen.availWidth

 

测试window.screen.availHeight 和 window.screen.availWidth

html code

<html>
<head>
<script type="text/javascript" >
function test()
{
    var h = window.screen.availHeight;
    alert("window.screen.availHeight = "+ h);
   
    var w = window.screen.availWidth;
    alert("window.screen.availWidth = "+ w);   
}
</script>
</head>
<body onload="test()"></body>
</html>

测试结果

分辨率:1024*768
availHeight:740
availWidth:1024

 

分辨率:1280*800
availHeight:772
availWidth:1280

 

分辨率:800*600
availHeight:572
availWidth:800

原创粉丝点击