document.body.scrollHeight在firefox/chrome中产生两种不同的结果

document.body.scrollHeight yielding two different results in firefox/chrome

本文关键字:两种 结果 scrollHeight body firefox chrome document      更新时间:2023-09-26

我正在尝试访问整个页面的高度(包括滚动)。在chrome中,document.body.scrollHeight可以执行此操作。在firefox中,这不起作用。。。firefox中的等价物是什么?

肯定会开始使用jquery,访问$(document).height()将为您完成所有浏览器检查。

http://api.jquery.com/height/

您可以使用jquery来完成此操作,而不会出现浏览器问题。

用户jQuery $(document).height()$(document).scrollTop()函数

<script type="text/javascript">
var scnWid,scnHei;
if (self.innerHeight) // all except Explorer
{
scnWid = self.innerWidth;
scnHei = self.innerHeight;
}
else if (document.documentElement && document.documentElement.clientHeight)
// Explorer 6 Strict Mode
{
scnWid = document.documentElement.clientWidth;
scnHei = document.documentElement.clientHeight;
}
else if (document.body) // other Explorers
{
scnWid = document.body.clientWidth;
scnHei = document.body.clientHeight;
} 
</script>