Full width home advertisement

Post Page Advertisement [Top]

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

No comments:

Post a Comment

Bottom Ad [Post Page]

| Designed by Colorlib