java获得窗体大小_javascript 获取窗口大小

var x = document.body.scrollLeft;

var y = document.body.scrollTop;

//获取屏幕宽度

availWidth = parseInt(window.screen.availWidth);

availHeight = parseInt(window.screen.availHeight);

//获取可见区域 宽度 高度

availWidth = parseInt(document.body.clientWidth);

availHeight = parseInt(document.body.clientHeight);

可见区域高度:document.body.clientHeight

总高度:document.body.scrollHeight

可见区域宽度:document.body.clientWidth

总宽度:document.body.scrollWidth

==============================================================

var getWindowInfo=function()

{

var scrollX=0,scrollY=0,width=0,height=0,contentWidth=0,contentHeight=0;

if(typeof(window.pageXOffset)=='number')

{

scrollX=window.pageXOffset;

scrollY=window.pageYOffset;

}

else if(document.body&&(document.body.scrollLeft||document.body.scrollTop))

{

scrollX=document.body.scrollLeft;

scrollY=document.body.scrollTop;

}

else if(document.documentElement&&(document.documentElement.scrollLeft||document.documentElement.scrollTop))

{

scrollX=document.documentElement.scrollLeft;

scrollY=document.documentElement.scrollTop;

}

if(typeof(window.innerWidth)=='number')

{

width=window.innerWidth;

height=window.innerHeight;

}

else if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight))

{

width=document.documentElement.clientWidth;

height=document.documentElement.clientHeight;

}

else if(document.body&&(document.body.clientWidth||document.body.clientHeight))

{

width=document.body.clientWidth;

height=document.body.clientHeight;

}

if(document.documentElement&&(document.documentElement.scrollHeight||document.documentElement.offsetHeight))

{

if(document.documentElement.scrollHeight>document.documentElement.offsetHeight){

contentWidth=document.documentElement.scrollWidth;

contentHeight=document.documentElement.scrollHeight;

}

else

{

contentWidth=document.documentElement.offsetWidth;

contentHeight=document.documentElement.offsetHeight;

}

}

else if(document.body&&(document.body.scrollHeight||document.body.offsetHeight))

{

if(document.body.scrollHeight>document.body.offsetHeight)

{

contentWidth=document.body.scrollWidth;

contentHeight=document.body.scrollHeight;

}else{

contentWidth=document.body.offsetWidth;

contentHeight=document.body.offsetHeight;

}

}

else

{

contentWidth=width;

contentHeight=height;

}

if(height>contentHeight)

height=contentHeight;

if(width>contentWidth)

width=contentWidth;

var rect=new Object();

rect.ScrollX=scrollX;

rect.ScrollY=scrollY;

rect.Width=width;

rect.Height=height;

rect.ContentWidth=contentWidth;

rect.ContentHeight=contentHeight;

return rect;

}

posted on 2007-05-25 13:34 Alpha 阅读(9794) 评论(6)  编辑  收藏 所属分类: JavaScript

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值