alert in embedded webview
When embedding WebView in an application and loading html-pages in开发者_JAVA技巧 it, JavaScripts alert() do not work.Give me an example pls
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;
}
}
精彩评论