onload事件:加载网页时触发
onresize事件:浏览器有任何尺寸变化时触发
test.html
1 <html> 2 <head> 3 <title>test</title> 4 <script type="text/javaScript" src = "test.js"></script> 5 </head> 6 <body onload = "calc()" onresize = "calc()"></body> 7 </html>
test.js
1 function calc(){ 2 var hight = document.body.clientHeight; 3 var width = document.body.clientWidth; 4 alert("hight is : " + hight + " width is : " + width); 5 }