【发布时间】:2015-12-02 07:21:54
【问题描述】:
我在 Windows 8 上。我有一个 JavaFX 应用程序,它创建一个带有 webview 控件的简单窗口并加载本地文件“test.html”。 "test.html" 包含 javascript(一个简单的 "alert("hello");")。 但是,javascript 被忽略。 JavaFX 中的 webview 使用什么渲染引擎? 我安装了 Firefox 和 IE。后者只有在用户接受的情况下才会执行包含在本地文件中的 JS。所以我的假设是,由于我的操作系统的某些配置,webview 使用 IE。这可能吗? 感谢您的帮助。
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Worker;
import javafx.concurrent.Worker.State;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.ScrollPane;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import netscape.javascript.JSObject;
public class Hello extends Application {
@Override
public void start(final Stage stage) {
stage.setWidth(400);
stage.setHeight(500);
Scene scene = new Scene(new Group());
WebView browser = new WebView();
WebEngine webEngine = browser.getEngine();
ScrollPane scrollPane = new ScrollPane();
scrollPane.setContent(browser);
String filepath = this.getClass().getResource("test.html").toExternalForm();
webEngine.load(filepath);
scene.setRoot(scrollPane);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
【问题讨论】: