【问题标题】:Html button click event detection in Android webviewAndroid webview中的Html按钮点击事件检测
【发布时间】:2017-07-28 12:37:09
【问题描述】:

嗨,我在 android webview 端成功获得了 html 按钮单击事件。当我的 html 文件在 android 资产文件夹中时它工作正常,但是当我使用 html 页面在线 url 时,它说在 Javascript 代码中找不到 Android 关键字。这是我的代码

//webview android addJavascriptInterface
 webView.addJavascriptInterface(new WebAppInterface(this), "Android"); 
public class WebAppInterface {
    Context mContext;
    WebAppInterface(Context c) {
        mContext = c;
    }
    @JavascriptInterface
    public void getViewId(String result) {
        Log.d("Sid", "click-----------" + result);
    }
}

我的 html 和 js 代码

</head>
<body>
    <button onClick="saveId('122');">1</button>
    <button onClick="saveId('222');">2</button>
    <img onclick="saveId('imgClickEvent')" src="file:///android_res/drawable/dtech.png"/>
</body>

<script language="javascript">

  function saveId(_id){
 //Android keyword not found how to solve it ?
    Android.getViewId(_id);
  }
</script>

【问题讨论】:

    标签: javascript android webview


    【解决方案1】:

    我找到了上述问题的解决方案。 Android (Android.getViewId(_id)) 关键字仅适用于 html 页面中的 javascript 而非外部 js 文件。

    【讨论】:

      猜你喜欢
      • 2011-05-03
      • 2014-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-25
      • 2011-12-30
      • 1970-01-01
      • 2018-06-04
      相关资源
      最近更新 更多