2013-04-10 67 views
7

.body.scrollHeight在Firefox中不起作用。.body.scrollHeight在Firefox中不起作用

请参见:http://jsfiddle.net/gjrowe/X63KR/

什么是改为使用正确的语法?

+0

这些页面似乎包含有关该问题的信息; http://www.webdeveloper.com/forum/showthread.php?73161-.scrollHeight-in-firefox,https://developer.mozilla.org/en-US/docs/DOM/element.scrollHeight,http:/ /stackoverflow.com/questions/4369990/scrollheight-property-in-firefox – 2013-04-10 17:38:50

+0

我得到了0的警报,但加入了一堆'
'似乎工作 – 2013-04-10 17:42:31

+0

@Allendar其他人没有回答相同的询问 – 2013-04-10 17:43:03

回答

18

这个问题有相同的原因造成的线程... Dynamically define iframe height based on window size (NOT CONTENT)

了解在该线程的问题会给解决这个。 http://james.padolsey.com/javascript/get-document-height-cross-browser/

+0

自从给出答案以来,在过去的3年中,此代码是否停止工作?我只是在Firefox中进行了测试,发现它与使用document.body.scrollHeight的效果相同。 – 2016-07-03 18:33:03

+0

@BrandonElliott我会测试它并回复你,但问题是由body.scrollHeight不可靠造成的。 – RSinohara 2016-11-15 17:39:26

0

使用下面的代码:

基本上,而是采用.body.scrollHeight,添加以下代码...从获得

function getDocHeight() { 
    var D = document; 
    return Math.max(
     Math.max(D.body.scrollHeight, D.documentElement.scrollHeight), 
     Math.max(D.body.offsetHeight, D.documentElement.offsetHeight), 
     Math.max(D.body.clientHeight, D.documentElement.clientHeight) 
    ); 
} 

答案

JavascriptExecutor jse = (JavascriptExecutor) (WebDriverObject); 
jse.executeScript("window.scrollBy(0,document.body.scrollHeight || document.documentElement.scrollHeight)", "");