本文介绍了警报在嵌入式网页视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当在其应用程序并加载HTML的页面中嵌入的WebView,JavaScript的警报()不work.Give我举一个例子PLS
When embedding WebView in an application and loading html-pages in it, JavaScripts alert() do not work.Give me an example pls
推荐答案
默认 WebChromeClient
的嵌入式浏览器实现将丢弃JavaScript警告,你应该重写 WebChromeClient
的实施与你自己的版本,这也可以让你在的地方一个默认的创建自己的自定义提醒,像这样的能力:
The default WebChromeClient
implemented by the embedded browser will discard javascript alerts, you should override the WebChromeClient
implementation with your own version, this also allows you the ability to create your own custom alerts in place of the default one like so:
browser.setWebChromeClient(new MyWebChromeClient());
...
final class MyWebChromeClient extends WebChromeClient {
@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
Log.d(LOG_TAG, message);
new AlertDialog.Builder(view.getContext()).setMessage(message).setCancelable(true).show();
result.confirm();
return true;
}
}
这篇关于警报在嵌入式网页视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!