不想在页面底部和右边显示滚动条,或者根据窗口大小控制层的大小?这个JavaScript函数或许对你有用!该函数在IE 6.0、Firefox 2.0、Netscape 8.1、Opera 9.24中均测试通过。
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){
- 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 = yScroll;
- } else {
- pageHeight = windowHeight;
- }
- if(xScroll < windowWidth){
- pageWidth = xScroll;
- } else {
- pageWidth = windowWidth;
- }
- arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
- return arrayPageSize;
- }
该函数返回的是一个数组,宽和高各有两个值,可以根据需要取舍。