网页宽度高度获取方法备忘
function gets()
{
var s ="网页可见区域宽:"+ document.body.clientWidth;
s += "<br>网页可见区域高:" + document.body.clientHeight;
s += "<br>网页可见区域宽:" + document.body.offsetWidth +" (包括边线的宽)";
s += "<br>网页可见区域高:" + document.body.offsetHeight +" (包括边线的宽)";
s += "<br>网页正文全文宽:" + document.body.scrollWidth;
s += "<br>网页正文全文高:" + document.body.scrollHeight;
s += "<br>网页被卷去的高:" + document.body.scrollTop;
s += "<br>网页被卷去的左:" + document.body.scrollLeft;
s += "<br>网页正文部分上:" + window.screenTop;
s += "<br>网页正文部分左:" + window.screenLeft;
s += "<br>屏幕分辨率的宽:" + window.screen.width;
s += "<br>屏幕分辨率的高:" + window.screen.height;
s += "<br>屏幕可用工作区宽度:" + window.screen.availWidth;
s += "<br>屏幕可用工作区高度:" + window.screen.availHeight;
document.getElementById('dd').innerHTML = s;
}
你可以参考下面这个函数,这个函数是获取完整页面尺寸的函数(即你说的浏览器能看到的区域,不包括被滚动条卷去的区域) -----------------------------js代码--------------------------------------------------------- <script> function GetPageSize(){ var xScroll, yScroll; if (window.innerHeight && window.scrollMaxY) { xScroll = document.body.scrollWidth; yScroll = window.innerHeight + window.scrollMaxY; } else if (document.body.scrollHeight > document.body.offsetHeight){ xScroll = document.body.scrollWidth; yScroll = document.body.scrollHeight; } else { xScroll = document.body.offsetWidth; yScroll = document.body.offsetHeight; } var windowWidth, windowHeight; if (self.innerHeight) { windowWidth = self.innerWidth; windowHeight = self.innerHeight; } else if (document.documentElement && document.documentElement.clientHeight) { windowWidth = document.documentElement.clientWidth; windowHeight = document.documentElement.clientHeight; } else if (document.body) { windowWidth = document.body.clientWidth; windowHeight = document.body.clientHeight; } if (yScroll < windowHeight){ pageHeight = windowHeight; } else { pageHeight = yScroll; } if (xScroll < windowWidth){ pageWidth = windowWidth; } else { pageWidth = xScroll; } arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) return arrayPageSize; } alert(GetPageSize()); </script> |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!