javascript .body.scrollHeight 在 Firefox 中不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15932650/
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
.body.scrollHeight doesn't work in Firefox
提问by G-J
.body.scrollHeight
does not work in Firefox.
.body.scrollHeight
在 Firefox 中不起作用。
See: http://jsfiddle.net/gjrowe/X63KR/
见:http: //jsfiddle.net/gjrowe/X63KR/
What is the correct syntax to use instead?
什么是正确使用的语法?
回答by G-J
This question has the same root problem as the thread at... Dynamically define iframe height based on window size (NOT CONTENT)
这个问题与线程在...具有相同的根本问题...根据窗口大小动态定义 iframe 高度(NOT CONTENT)
Understanding the issue at that thread will give the solution to this.
了解该线程中的问题将提供解决方案。
Basically, instead of using .body.scrollHeight
, add this code...
基本上,不是使用,而是.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)
);
}
The answer was obtained from: http://james.padolsey.com/javascript/get-document-height-cross-browser/
答案来自:http: //james.padolsey.com/javascript/get-document-height-cross-browser/
回答by Ankit Gupta
Use below code:
使用以下代码:
JavascriptExecutor jse = (JavascriptExecutor) (WebDriverObject);
jse.executeScript("window.scrollBy(0,document.body.scrollHeight || document.documentElement.scrollHeight)", "");