实时获取浏览器的窗口大小

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 }

 

posted @ 2016-07-29 10:56  月色深潭  阅读(264)  评论(0编辑  收藏  举报