实时获取浏览器的窗口大小
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 }
本文来自博客园,作者:月色深潭,交流群:733423266,转载请注明原文链接:https://www.cnblogs.com/moonpool/p/5717486.html