您好,欢迎访问一九零五行业门户网

准确获得页面、窗口高度及宽度的JS_javascript技巧

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 pageheight = windowheight;
} else {
pageheight = yscroll;
}
// for small pages with total width less then width of the viewport
if(xscroll 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 pageheight = yscroll; 
} else { 
pageheight = windowheight; 
}
// for small pages with total width less then width of the viewport 
if(xscroll pagewidth = xscroll; 
} else { 
pagewidth = windowwidth; 
}
其它类似信息

推荐信息