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

时间:2012-01-13 21:16:56

标签: javascript css

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

3 个答案:

答案 0 :(得分:2)

您可以使用jquery在没有浏览器问题的情况下执行此操作。

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

答案 1 :(得分:1)

肯定开始使用jquery,访问$(document).height()会为你做所有的浏览器检查。

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

答案 2 :(得分:1)

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