Loading local JavaScript file in WebView in Java 8u60

拟墨画扇 提交于 2019-11-28 07:59:40

问题


Until Java 8u51, the following worked fine:

  • Have an HTML file containing <script src="javascript.js"></script>
  • Load this HTML file into a WebView
  • Call a function contained in javascript.js using webView.getEngine().executeScript()

After switching to 8u60 however, it no longer works:

Exception in thread "JavaFX Application Thread" netscape.javascript.JSException: TypeError: undefined is not a function

So the file javascript.js is no longer loaded. It works when started from an IDE, where JavaScript file just lies on the file system. However, it no longer works when the application is packaged and therefore javascript.js is inside a JAR file.

Any idea what has changed and how this can be fixed?


回答1:


Since Java 8u60, local javascript files referenced in html files are not executed anymore in the WebView. When running the program with an older version, it still works. I found no information that this change in behaviour was intended by Oracle.

As a workaround you can either place the javascript code directly into the HTML file, or load in java the contents of the javascript file into a String and execute it with webView.getEngine().executeScript()



来源:https://stackoverflow.com/questions/32429069/loading-local-javascript-file-in-webview-in-java-8u60

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!