JS获取当前窗口的宽和高
window.onload = function(){
document.onclick = function(){
//输出当前窗口的宽
var windowWidth = document.documentElement.clientWidth || document.body.clientWidth;
alert(windowWidth);
//输出当前窗口的高
var windowHeight = document.documentElement.clientHeight || document.body.clientHeight;
alert(windowHeight);
}
}

该博客介绍了如何使用JavaScript在页面加载完成后及点击事件触发时,实时获取当前窗口的宽度和高度。通过document.documentElement或document.body分别获取窗口的clientWidth和clientHeight,实现对窗口尺寸变化的监测。
1万+

被折叠的 条评论
为什么被折叠?



