问题描述
我已经覆盖了我的 WebChromeClient 的 onJsAlert 行为,例如:
I have override my WebChromeClient's onJsAlert behavior like:
WebChromeClient wvcc = new WebChromeClient() {
@Override
public boolean onJsAlert(WebView view, String url, String message, final JsResult result) {
//...
return true;
}
}
我的应用程序成功处理了 Js 警报并抑制了原始警报.但是,在警报事件发生后,我无法再单击 web 视图中网页上的按钮(在列表视图的列表项中).我目前正在使用 jquery mobile 来构建我的网站.
my application successfully handle the Js alerts and suppressed the original alert. However, after the alert event, I can no longer click my buttons(in list-items of listview) on the web page in my webview.I am currently using jquery mobile to build my web.
还有什么我应该注意的吗?
Is there anything else I should aware of?
推荐答案
我刚刚遇到了完全相同的问题.我想生成一个自定义的 android 对话框而不是警报,这是最终的解决方案:
I just faced the exactly same problem. I wanted to generate a custom android dialog instead of the alert, to this is the final solution:
myWebView.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onJsAlert(WebView view, final String url, String message,
JsResult result) {
AlertDialog.Builder builder = new AlertDialog.Builder(
MainActivity.this);
builder.setMessage(message)
.setNeutralButton("OK", new OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
arg0.dismiss();
}
}).show();
result.cancel();
return true;
}
});
关键是result.cancel();
和return true;
,我测试了几种组合,唯一没有触发默认JS警报的并且没有导致触摸问题是这种组合
The key is the result.cancel();
and return true;
, I tested in several combinations, and the only one that did not fired the default JS alert AND didn't caused the touch problem was this combination
这篇关于onJsAlert 没有响应点击后的 Android webview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!