0

I am filling the user name box automaticly in webview application. But ı need to fill the blanks with wariable which defined in java code here is my code. I want to use variable in my java code instade of "PASS" and "NAME"

javascript:

document.getElementById('horde_user').value='NAME';" +"javascript:document.getElementById('horde_pass').value='PASS';"

java:

final String js =  "javascript:document.getElementById('horde_user').value='NAME';" +"javascript:document.getElementById('horde_pass').value='PASS';"+"javascript:documentgetElementsByName('login_button')[0].click()";
webview.setWebViewClient(new WebViewClient() {
    public void onPageFinished(WebView view, String url){
        if(Build.VERSION.SDK_INT >= 19){
            view.evaluateJavascript(js, new ValueCallback<String>() {
                @Override
                public void onReceiveValue(String s) {
                }
            });
        }
    }
});
Jakob F
  • 1,046
  • 10
  • 23

1 Answers1

1

I recommend you to create a javascript function like :

function login(NAME, PASS)
{
    document.getElementById('horde_user').value=pass;
    document.getElementById('horde_pass').value=id;
    document.getElementsByName('login_button')[0].click();
}

And then from your app code

String id = "myid"; //Get val from the dialog
String pass = "mypass"; //Get val from the dialog
webview.loadUrl("javascript:login('"+NAME+"','"+PASS+"')");

if you need call java from js you can folow this post Hope it helps ;)

Majid Sadrayi
  • 324
  • 2
  • 6