javascriptjavafxjavafx-8javafx-webengine

Workaround for JavaFX Webview not supporting window.FileReader javascript


The following code indicates that the JavaFX Webview does not support the Javascript window.FileReader api:

webEngine.loadContent("<html><body><script>alert(window.FileReader);</script></body></html>

Are there any known workarounds?


Solution

  • It does support FileReader. The problem is webengine/webview does not display alert boxes, confirmation boxes, or popup windows without some work on your part so that is actually what is failing. If you want alert boxes you need to create the dialog yourself:

        webEngine.setOnAlert
        (
            new EventHandler<WebEvent<String>>()
            {
                @Override
                public void handle(WebEvent<String> arg0) 
                {
                    Alert alert = new Alert(AlertType.INFORMATION);
                    alert.setHeaderText("Alert");
                    alert.setContentText(arg0.getData());
                    alert.showAndWait();
                }
            }
        );