当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 准确获得页面、窗口高度及宽度的JS

Javascript
各种浏览器兼容问题
取得父标签
JS用 或 || 来兼容FireFox!
JavaScript的Function详细
关于IE只能嵌套27层表格的说法证明
xmlHTTP返回值重编码的优化
静态网页加密
来访统计
炽热的文字
发一个分页的js
琥珀无限级联动菜单-JavaScript版
用javascript连接access数据库的方法
用js得到网页中所有的div的id
cloneNode实现表格增加删除效果
支持IE和FF的div+css选项卡
arguments对象
使两个iframe的高度与内容自适应,且相等
云网广告中的代码,提示出错,大家找找
document.all与WEB标准
表单内同名元素的控制

Javascript 中的 准确获得页面、窗口高度及宽度的JS


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 301 ::
收藏到网摘: n/a

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;
}
有幸找到了你的这个东东,帮我解决了问题,不过仔细看了下,好象大大的有点问题,参数值和名称上看好象有点对不上号哦.
// for small pages with total height less then height of the viewport
if(yScroll < windowHeight){
pageHeight = yScroll;
} else {
pageHeight = windowHeight;
}
// for small pages with total width less then width of the viewport
if(xScroll < windowWidth){
pageWidth = xScroll;
} else {
pageWidth = windowWidth;
}