javascript document.body.scrollHeight 在 firefox/chrome 中产生两种不同的结果
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8857341/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
document.body.scrollHeight yielding two different results in firefox/chrome
提问by deruse
I am trying to get access to the height of the entire page (including scrolling). In chrome, document.body.scrollHeight does this. In firefox, this doesn't work... what is the equivalent in firefox?
我正在尝试访问整个页面的高度(包括滚动)。在 chrome 中,document.body.scrollHeight 就是这样做的。在 Firefox 中,这行不通…… Firefox 中的等价物是什么?
回答by sonjz
definitely start using jquery, accessing $(document).height() will do all the browser checks for you.
一定要开始使用 jquery,访问 $(document).height() 会为你做所有的浏览器检查。
回答by FURKAN ILGIN
You can use jquery to do this without browser problem.
您可以使用 jquery 执行此操作而不会出现浏览器问题。
User jQuery $(document).height()
and $(document).scrollTop()
functions
用户 jQuery $(document).height()
和$(document).scrollTop()
函数
回答by Travis J
<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>