//获取浏览器可视区域高度
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;
}
本文介绍了一种通过JavaScript获取浏览器可视区域高度及网页内容实际高度的方法。针对不同浏览器(如IE6, IE7, IE8, Chrome, Firefox)的特性,提供了一套兼容性强的解决方案。
466

被折叠的 条评论
为什么被折叠?



