2013-04-10 8 views
7

.body.scrollHeightはFirefoxでは動作しません。Firefoxで.body.scrollHeightが動作しない

参照: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 –

+0

アラートに0が表示されましたが、「
」の束を追加した後に動作するようです。 –

+0

@Allendar他の人が同じ質問をしています –

答えて

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を使用した場合と同じ値が得られることがわかりました。 –

+0

@BrandonElliott私はそれをテストしてあなたに戻ってきますが、問題はbody.scrollHeightが信頼できないことが原因です。 – RSinohara

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)", ""); 
関連する問題