Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Internet explorer给出的网页总高度为;0“;_Javascript_Internet Explorer_Offsetheight - Fatal编程技术网

Javascript Internet explorer给出的网页总高度为;0“;

Javascript Internet explorer给出的网页总高度为;0“;,javascript,internet-explorer,offsetheight,Javascript,Internet Explorer,Offsetheight,我尝试使用javascript获取网页的总高度,如下所示 var pageHeight=(document.height!==未定义)?document.height:document.body.offsetHeight 在其他浏览器中工作正常,但Internet explorer会为其返回值“0”。为什么?这应该适用于所有浏览器: var pageHeight = Math.max(document.height, document.body.scrollHeight, documen

我尝试使用javascript获取网页的总高度,如下所示

var pageHeight=(document.height!==未定义)?document.height:document.body.offsetHeight


在其他浏览器中工作正常,但Internet explorer会为其返回值“0”。为什么?

这应该适用于所有浏览器:

var pageHeight = Math.max(document.height, document.body.scrollHeight,
    document.body.offsetHeight);
不要忘记在加载文档后执行代码


编辑:我希望它能工作,但我没有办法在所有浏览器中测试它,我不是100%确定。它是根据jQuery的源代码改编的。

哪个版本的IE?他们的版本就像黑白一样不同。@techfoobar IE 10。最新的!您的代码在IE9和IE10中都运行良好,请参阅。我认为造成您困惑的原因是,所有浏览器对远视的概念都不一样-它与视口不同,我认为您正在寻找它。如果您在IE10中,您是否检查过您的页面实际上处于IE10标准模式,而不是兼容模式或怪癖模式。IE10本身应该没问题,但这些旧模式肯定会出现上述问题。@dystroy提醒NaN:(对于加载文档后执行的代码,我认为它已经得到了处理,因为它可以在其他浏览器中工作