Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android webview :How to change javaScript alert title text in android webview?

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 ?

like image 378
Mukesh Y. Avatar asked Jun 27 '16 12:06

Mukesh Y.


1 Answers

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;
    } }); 
like image 82
Mukesh Y. Avatar answered Sep 26 '22 02:09

Mukesh Y.