在Java 8u60中的WebView中加载本地JavaScript文件 [英] Loading local JavaScript file in WebView in Java 8u60

查看:125
本文介绍了在Java 8u60中的WebView中加载本地JavaScript文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

直到Java 8u51,以下各项都可以正常工作:

Until Java 8u51, the following worked fine:

  • 具有一个包含<script src="javascript.js"></script>
  • 的HTML文件
  • 将此HTML文件加载到WebView
  • 使用webView.getEngine().executeScript()
  • 调用javascript.js中包含的函数
  • 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()

但是,切换到8u60后,它不再起作用:

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

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

因此不再加载文件javascript.js.从IDE启动时,它可以工作,其中JavaScript文件仅位于文件系统上.但是,打包应用程序后它不再起作用,因此javascript.js在JAR文件中.

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?

推荐答案

自Java 8u60起,在WebView中不再执行html文件中引用的本地javascript文件.当使用旧版本运行该程序时,它仍然可以工作. 我没有发现这种行为改变是Oracle故意的.

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.

作为一种解决方法,您可以将javascript代码直接放置到HTML文件中,或者将javascript文件的内容加载到String中并用webView.getEngine().executeScript()

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()

这篇关于在Java 8u60中的WebView中加载本地JavaScript文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆