2013-04-10 39 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)", "");