网页宽度高度获取方法备忘

function gets()
{
var s ="网页可见区域宽:"+ document.body.clientWidth;
s += "<br>网页可见区域高:" + document.body.clientHeight;
s += "<br>网页可见区域宽:" + document.body.offsetWidth +" (包括边线的宽)";
s += "<br>网页可见区域高:" + document.body.offsetHeight +" (包括边线的宽)";
s += "<br>网页正文全文宽:" + document.body.scrollWidth;
s += "<br>网页正文全文高:" + document.body.scrollHeight;
s += "<br>网页被卷去的高:" + document.body.scrollTop;
s += "<br>网页被卷去的左:" + document.body.scrollLeft;
s += "<br>网页正文部分上:" + window.screenTop;
s += "<br>网页正文部分左:" + window.screenLeft;
s += "<br>屏幕分辨率的宽:" + window.screen.width;
s += "<br>屏幕分辨率的高:" + window.screen.height;
s += "<br>屏幕可用工作区宽度:" + window.screen.availWidth;
s += "<br>屏幕可用工作区高度:" + window.screen.availHeight;
document.getElementById('dd').innerHTML = s;
}

你可以参考下面这个函数,这个函数是获取完整页面尺寸的函数(即你说的浏览器能看到的区域,不包括被滚动条卷去的区域)
-----------------------------js代码---------------------------------------------------------
<script>
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 = windowHeight;
    } else { 
        pageHeight = yScroll;
    }
    if(xScroll < windowWidth){ 
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }
    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
    return arrayPageSize;
}
alert(GetPageSize());
</script>

 

posted on 2013-08-26 14:32  空明流光  阅读(242)  评论(0编辑  收藏  举报

导航