常用的宽度属性 :
屏幕分辨率的宽:window.screen.width;
网页可见区域宽:document.body.clientWidth(不包括边框);
网页可见区域宽:document.body.offsetWidth(包括边框的宽);
与之相对应的高度属性window.screen.height;document.body.height;document.body.offsetHeight.
利用这些属性,即可获取浏览器窗口的相关属性。
简单示例:
<head>
<title></title>
<meta http-equiv="content-type" content="text/html charset=utf-8">
</head>
<body>
<input type="button" value="测试" id="btn1"
style="width: 60px;border: 1px solid green;margin: 10px"/>
<script>
function func1(){
var btn=document.getElementById("btn1");
var len=document.body.clientWidth;
btn.value=len;
}
func1();
window.οnresize=func1;
</script>
</body>