Android webview: How to change JavaScript alert title text in android webview?

Issue

In my Android application I have used web view inside web view I have a button. On clicking that button I am calling a JavaScript function that JavaScript function have an alert box. In that alert title is showing (The page at "file://" says). I want to change this title to my custom text.
How to change that title?

Solution

I have solved this problem by implementing the setWebChromeClient:

webView.setWebChromeClient(new WebChromeClient() {

    @Override
    public boolean onJsAlert(WebView view, String url, String message, final JsResult result) {
        AlertDialog dialog = new AlertDialog.Builder(view.getContext()).
                setTitle("YourAlertTitle").
                setMessage(message).
                setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        //do nothing
                    }
                }).create();
        dialog.show();
        result.confirm();
        return true;
    } }); 

Answered By – Mukesh Y.

Answer Checked By – David Marino (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *