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;
}


 

原文地址:https://www.cnblogs.com/xiongbaobao/p/2393440.html