java - 你怎么知道一个webview有一些JS功能?
问题描述
我们知道Java可以通过'webView.getEngine().executeScript("setServerStatus('xxxxx')")'的形式调用javafx webview中的js函数,但是有时候切换HTML页面时却找不到js函数。在后台,我使用线程实时更新HTML页面的网络状态,它有时会报告以下异常:
Exception in thread "JavaFX Application Thread" netscape.javascript.JSException: ReferenceError: Can't find variable: setServerStatus
at com.sun.webkit.dom.JSObject.fwkMakeException(JSObject.java:146)
at com.sun.webkit.WebPage.twkExecuteScript(Native Method)
at com.sun.webkit.WebPage.executeScript(WebPage.java:1509)
at javafx.scene.web.WebEngine.executeScript(WebEngine.java:1005)
at com.gzhuiqun.adapter.Application.lambda$4(Application.java:370)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:748)
Java是否提供了判断当前HTML中是否存在js函数的方法?或者更优雅的方式来做到这一点?在webview html5中,正常的js监控网络状态功能无效。
解决方案
推荐阅读
- android - Android - Kotlin - Retrofit2 | @Query 不工作
- spring - Spring实体到DTO的转换
- windows - 在 Docker 中启动 tomcat 时无法在端口 8080 上打开网页
- linux - 用另一种格式替换具有特定格式的单词
- scala - 在每个文件的播放路线文件中定义导入
- r - 如何使 n() 在 tidyverse 中也不计算 NA?
- javascript - createClient 有问题
- r - R中geom_step的饱和曲线
- java - Windows 10 上的 JComboBox 类中的方法 contentsChanged 缓慢
- javascript - 为什么会突然 req.body 为空?