开发者

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;
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜