<html>
<head> <title>51windows.Net </title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <style type="text/css"> </style> </head> <body> <SCRIPT LANGUAGE="JavaScript"> var s = ""; s += "/r/n网页可见区域宽:"+ document.body.clientWidth; s += "/r/n网页可见区域高:"+ document.body.clientHeight; s += "/r/n网页可见区域宽:"+ document.body.offsetWidth +" (包括边线的宽)"; s += "/r/n网页可见区域高:"+ document.body.offsetHeight +" (包括边线的宽)"; s += "/r/n网页正文全文宽:"+ document.body.scrollWidth; s += "/r/n网页正文全文高:"+ document.body.scrollHeight; s += "/r/n网页被卷去的高:"+ document.body.scrollTop; s += "/r/n网页被卷去的左:"+ document.body.scrollLeft; s += "/r/n网页正文部分上:"+ window.screenTop; s += "/r/n网页正文部分左:"+ window.screenLeft; s += "/r/n屏幕分辨率的高:"+ window.screen.height; s += "/r/n屏幕分辨率的宽:"+ window.screen.width; s += "/r/n屏幕可用工作区高度:"+ window.screen.availHeight; s += "/r/n屏幕可用工作区宽度:"+ window.screen.availWidth; alert(s); </SCRIPT> </body> </html>
搞了大半天,总算弄明白了为何用document.body.clientHeight,document.body.offsetHeight都没有办法获取网页可见区域的正确值,原来罪魁祸首是W3C定义的标准!!在新定义出来的标准下 document.documentElement.clientHeight在IE和火狐里都能获取正确值,下面一篇文章详细介绍了获取各种浏览器可见窗口大小这方面的差别:
<scrīpt> 在IE中: 原文地址:http://www.css88.com/article.asp?id=133 判断浏览器的类型: 获取浏览器区域的大小://
var yScroll;
if (self.pageYOffset) {
yScroll = self.pageYOffset; } else if (document.documentElement && document.documentElement.scrollTop){ // Explorer 6 Strict yScroll = document.documentElement.scrollTop; } else if (document.body) {// all other Explorers yScroll = document.body.scrollTop; }
arrayPageScroll = new Array('',yScroll)
return arrayPageScroll; }
//
// getPageSize() // Returns array with page width, height and window width, height // Core code from - quirksmode.org // Edit for Firefox by pHaez // 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){ // all but Explorer Mac xScroll = document.body.scrollWidth; yScroll = document.body.scrollHeight; } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari xScroll = document.body.offsetWidth; yScroll = document.body.offsetHeight; } var windowWidth, windowHeight; if (self.innerHeight) { // all except Explorer windowWidth = self.innerWidth; windowHeight = self.innerHeight; } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode windowWidth = document.documentElement.clientWidth; windowHeight = document.documentElement.clientHeight; } else if (document.body) { // other Explorers windowWidth = document.body.clientWidth; windowHeight = document.body.clientHeight; } // for small pages with total height less then height of the viewport if(yScroll < windowHeight){ pageHeight = windowHeight; } else { pageHeight = yScroll; }
// for small pages with total width less then width of the viewport
if(xScroll < windowWidth){ pageWidth = windowWidth; } else { pageWidth = xScroll; } arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) return arrayPageSize; } |
WEB页面各种尺寸说明
最新推荐文章于 2018-04-02 09:55:43 发布