2

I'm trying to figure out how i can handle Javascript pop's in a webview, I have a WebView that is viewing a admin screen of a device on my network. Similar to a router, It has a administration section that then prompts a dialog box with a Username and Pswd field, However in my WebView i get no popup and instead get a 401 Error.

Great example of handling the dialog popup box is in Dolphin browser, they have provided a custom dialog with the two username and password fields.

I believe the below code is what i need to handle the Javascript for the pop up, however i need to create ad username and password dialog that will input the string's that are needed by the webpage.

Any idea's, recommendations, source code, is really appreciated. Thanks,

  public boolean onJsAlert(WebView view, String url, String message, final JsResult result) 
        {
            new AlertDialog.Builder(Mosembro.this)
                .setTitle("javaScript dialog")
                .setMessage(message)
                .setPositiveButton(android.R.string.ok,
                        new AlertDialog.OnClickListener() 
                        {
                            public void onClick(DialogInterface dialog, int which) 
                            {
                                result.confirm();
                            }
                        })
                .setCancelable(false)
                .create()
                .show();

            return true;
        };
Jaison Brooks
  • 5,816
  • 7
  • 43
  • 79
  • I see you got the coding part right here, just confirming did you bind a 'webchrome client' and setJavascriptEnabled(true) on your webview? because same thing is working at my end. – Darpan May 31 '13 at 12:45

1 Answers1

0

Take a look at this SO post.

Apparently WebView can't get the HTTP response. By creating your own custom WebViewClient class, you can 'intercept' the HTTP header and pull the response code.

Community
  • 1
  • 1
crocboy
  • 2,887
  • 2
  • 22
  • 25