您的位置:首页 > Web前端 > JavaScript

JS 获取网页内容高度 和 网页可视高度 支持IE 6789 Firefox Chrome

2011-02-24 10:20 591 查看
1 function getClientHeight()
2 {
3 //可见高
4 var clientHeight=document.body.clientHeight;//其它浏览器默认值
5 if(navigator.userAgent.indexOf("MSIE 6.0")!=-1)
6 {
7 clientHeight=document.body.clientHeight;
8 }
9 else if(navigator.userAgent.indexOf("MSIE")!=-1)
{
//IE7 IE8
clientHeight=document.documentElement.offsetHeight
}

if(navigator.userAgent.indexOf("Chrome")!=-1)
{
clientHeight=document.body.scrollHeight;
}

if(navigator.userAgent.indexOf("Firefox")!=-1)
{
clientHeight=document.documentElement.scrollHeight;
}
return clientHeight;
}

//获得网页内容高度
function getContentHeight()
{
//可见高
var ContentHeight=document.body.scrollHeight;//其它浏览器默认值

if(navigator.userAgent.indexOf("Chrome")!=-1)
{
ContentHeight= document.body.clientHeight;
}

if(navigator.userAgent.indexOf("Firefox")!=-1)
{
ContentHeight=document.body.offsetHeight;
}
return ContentHeight;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐