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

function getClientHeight()
{
//可见高
var clientHeight=document.body.clientHeight;//其它浏览器默认值
if(navigator.userAgent.indexOf("MSIE 6.0")!=-1)
{
clientHeight=document.body.clientHeight;
}
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;
}


 

posted @ 2012-03-13 11:09  李小熊  阅读(282)  评论(0编辑  收藏  举报