WebView监听HTML的事件

Kornan
2020-10-26 / 0 评论 / 246 阅读 / 正在检测是否收录...

添加addJavascriptInterface

val ws: WebSettings = wv.getSettings()
ws.javaScriptEnabled = true
wv.addJavascriptInterface(object : Any() {
      @JavascriptInterface 
      fun performClick(strl: String) {
           Toast.makeText(this@YourActivity, stringVariable, Toast.LENGTH_SHORT).show()
      }
}, "ok")

在onclick中添加对应方法,这里的"ok"是addJavascriptInterface的name参数

<button type="button" onclick="ok.performClick();">OK</button>
0

评论 (0)

取消