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);
}
}