开发者

alert in embedded webview

开发者 https://www.devze.com 2023-01-02 21:51 出处:网络
When embedding WebView in an application and loading html-pages in开发者_JAVA技巧 it, JavaScripts alert() do not work.Give me an example plsThe default WebChromeClient implemented by the embedded brow

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

精彩评论

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