JavaFX WebView不执行JavaScript

时间:2015-09-06 18:18:13

标签: webview javafx

我在Windows 8上。我有一个JavaFX应用程序,它创建一个带有webview控件的简单窗口并加载本地文件“test.html”。 “test.html”包含javascript(简单的“alert(”hello“);<(script>”)。 但是,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);
    }
}

0 个答案:

没有答案