JS获取页面窗口实际大小函数
作者:银子 来源:银子的blog 时间:2008-01-28 13:18:00
Lightbox里面的一个函数,能把页面实际的高宽与浏览器可视面积的高宽保存在一个数组中..非常好用.
什么是Lightbox?下载lightbox源代码? -->Lightbox JS v2.0
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;
}
调用方法:
var getPageSize = getPageSize();
alert(getPageSize[0] + getPageSize[1] + getPageSize[2] + getPageSize[3]);
getPageSize[0]保存的是页面宽度,getPageSize[1]保存的是页面高度,getPageSize[2]保存的是窗口宽度,getPageSize[3]保存的是窗口高度。
标签:窗口,页面,宽度,函数,js
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
谈谈网页一屏有多大?
2007-12-21 12:28:00
![](https://img.aspxhome.com/file/UploadPic/200712/21/2007122112356981s.jpg)
如何判断JavaScript变量的类型
2009-02-25 12:28:00
阿里巴巴中秋节logo设计的艰辛曲折过程
2008-09-11 17:15:00
![](https://img.aspxhome.com/file/UploadPic/20089/11/2008911171924597s.jpg)
二级联动下拉菜单javascript源码
2010-03-16 12:32:00
chr(9)、chr(10)、chr(13)、chr(32)与特殊空格
2009-07-03 15:26:00
WEB2.0网页制作标准教程(12)XHTML校验及常见错误
2008-02-19 19:59:00
![](https://img.aspxhome.com/file/UploadPic/20082/19/2008219201419762s.gif)
参数传递解决window.open的session变量丢失
2007-10-22 17:40:00
JS通过FSO将unicode字符写入文本
2009-06-01 12:26:00
网页设计趋势之:”勾引”用户的按钮
2009-02-17 12:09:00
![](https://img.aspxhome.com/file/UploadPic/20092/17/but-500x47-23s.gif)
Frontpage2003的怪bug,自动添加“../”的父级目录
2007-09-30 13:30:00
![](https://img.aspxhome.com/file/UploadPic/20079/30/2007930133147256s.jpg)
Mootools 1.2教程(7)——设置和获取样式表属性
2008-11-25 13:48:00
ASP生成XML文件
2009-06-29 16:28:00
小诀窍让你快速上手Dreamweaver
2007-12-03 11:35:00
怎样从旧版本SQL Server中重新存储数据
2009-01-15 13:23:00
MYSQL server has gone away解决办法
2010-11-25 17:22:00
有关于IE8 Beta 1两个提醒
2008-05-15 12:32:00
[JS效果]动画效果打开/关闭/移动层
2008-04-10 11:42:00
SQL学习笔记二 创建表、插入数据的语句
2011-09-30 11:17:32
一些实用的sql语句
2009-11-10 20:21:00
两个2008北京奥运会倒计时js代码
2008-06-11 13:26:00