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) {
                }
            });
        }
    }
});

1 Answer 1

2

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 ;)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.