• Thursday, February 11, 2016

    Android - How to show javascript alert in WebView

    How to show javascript alert in WebView?

    In android, WebView does not show javascript alert dialog in activity. Here I give a solution that can easily handle the alert dialog with user customization. 

    Write the following code under activity after initiating the WebView.

    WebView wv= (WebView) findViewById(R.id.webView);
    final Context mc=this;

    wv.setWebChromeClient(new WebChromeClient() {
        public boolean onJsAlert(WebView view, String url, String message, final JsResult result) {
            new AlertDialog.Builder(mc)
                    .setPositiveButton("Button Text", new AlertDialog.OnClickListener() {
                        public void onClick(DialogInterface dialogInterface, int i) {
            return true;

    If there is any error after implementing this code and let us know. 

    KeyWords: Android WebView JavaScript Alert

    Syed Masoom Rizvi

    Author & Editor

    Hi, This is Syed Masoom Rizvi, who is continue exploring the world of programming ,programming and programming... :)


    Post a Comment