您可以使用以下调用获取WebView中显示的文档高度:
webView.getEngine().executeScript(
"window.getComputedStyle(document.body, null).getPropertyValue('height')"
);
Run Code Online (Sandbox Code Playgroud)
一个完整的应用程序来演示呼叫使用:
import javafx.application.Application;
import javafx.beans.value.*;
import javafx.scene.Scene;
import javafx.scene.web.*;
import javafx.stage.Stage;
import org.w3c.dom.Document;
public class WebViewHeight extends Application {
@Override public void start(Stage primaryStage) {
final WebView webView = new WebView();
final WebEngine engine = webView.getEngine();
engine.load("http://docs.oracle.com/javafx/2/get_started/animation.htm");
engine.documentProperty().addListener(new ChangeListener<Document>() {
@Override public void changed(ObservableValue<? extends Document> prop, Document oldDoc, Document newDoc) {
String heightText = webView.getEngine().executeScript(
"window.getComputedStyle(document.body, null).getPropertyValue('height')"
).toString();
double height = Double.valueOf(heightText.replace("px", ""));
System.out.println(height);
}
});
primaryStage.setScene(new Scene(webView));
primaryStage.show();
}
public static void main(String[] args) { launch(args); }
}
Run Code Online (Sandbox Code Playgroud)
以上答案来源:Oracle JavaFX论坛WebView配置线程.
针对相关功能的基于Java的API的相关问题跟踪器请求:
归档时间: |
|
查看次数: |
3467 次 |
最近记录: |