1
我在Windows 8上。我有一个JavaFX应用程序,它创建一个带有webview控件的简单窗口并加载本地文件“test.html”。 “test.html”包含javascript(一个简单的“alert(”hello“); <(script>”)。 但是,javascript被忽略。 我在Firefox和IE中安装了web浏览器。包含在本地文件只有在用户接受这样做,则后者执行JS。因此,我的假设是,网页流量使用IE浏览器,由于我的OS的一些配置。这可能吗? 感谢您的帮助。JavaFX WebView不执行JavaScript
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);
}
}