Get javascript var from webview to android var

1.1k views Asked by At

I am trying get a var from a webview but I only can modify like this:

browser.loadUrl("javascript:var x = document.getElementById('login').value = 'something';");

but I need get any js var like this :

String myAndroidvar = browser.loadUrl("javascript:var x = document.getElementById('login').value");

but this syntax is incorrect, I need the correct method.

1

There are 1 answers

0
Erik Duisters On

You have to add a javaScriptInterface to you webview. See this blog for a decent description. You can also get stuff from javascript by calling an interface function you defined using:

web.loadUrl("javascript: window.jsinterface.getValue(document.getElementById('login').value)");