问题
I am trying to integrate the mozilla viewer in a JavaFx WebView by using the following code:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
public class TestStrict extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
WebView webView = new WebView();
String url = TestStrict.class.getClassLoader().getResource("pdfjs-1.1.366-dist/web/viewer.html").toExternalForm();
webView.getEngine().load(url);
Scene scene = new Scene(webView);
primaryStage.setScene(scene);
primaryStage.setWidth(800);
primaryStage.setHeight(600);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
The pdfjs-1.1.366-dist folder is downloaded from pdfjs GitHub
I also changed the viewer.html
just to add firebug-lite inside:
<script type='text/javascript' src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>
Now when I run the application I get the viewer frame but without the default pdf loaded and the following error is inside firebug console:
"TypeError: undefined is not an object (evaluating 'globalScope.PDFJS') (pdf.worker.js,103)"
I removed all the 'use strict' directives in the javascript files and everything is working fine.
I don't know if this is a bug in JavaFX or internal WebKit but it happens with version 1.8.0_60.
So is there any way that I can disable strict mode since there will be other web pages that will be loaded where I can't control the scripts and remove 'use strict' directives?
来源:https://stackoverflow.com/questions/33258381/how-to-tell-javafx-webview-to-ignore-use-strict-directive