是否可以在 Android 中创建事件,将数据发送到 WebView 中的 Havascript EventListener?
例如:
在后台,我启动线程搜索服务器上的更新。找到更新后,我发送事件以更新用户页面上的数据。我不想重新加载 View 。
最佳答案
目前我发现的唯一方法是使用 JavaScript 注入(inject):
mWebView.loadUrl("javascript:helloWorld(\"hi\");"); //or postUrl if using HTTP POST
这将导致在网页的 JavaScript 中定义的函数 helloWorld
被调用,参数值为 hi
。
关于javascript - Android 自定义事件转 Javascript EventListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10615933/