【发布时间】: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