0

i would like to have full control over the webview control. for instance, i would like to know if it is navigating or if it has completed navigating to the desired page. I would then wish to push same data from the app like the user name and password to a field on the page that was opened by the webview. Could you point me to some examples or tutorials please? Thank you!

user3267567
  • 524
  • 4
  • 14

1 Answers1

0

Rely on the following post for javascript injection: Inject javascript into WebChromeClient

Now just change the underlying javascript. It is important to understand that the Javascript directly is affected by the HTML, so if the HTML is changed, the Javascript (and probably also your app, require an update).

So in case you got the following HTML:

<form action="#" autocomplete="on">
    <input type="text"     name="username" placeholder="Username" />
    <input type="password" name="password" placeholder="Password" />
    <button type="submit">Login</button>
</form>

The javascript would look like the following, to

  1. set the username
  2. set the password
  3. autologin by clicking login button
$('input[name=\"username\"]').val('%@'); // 1.
$('input[name=\"password\"]').val('%@'); // 2.
$('.login').click(); // 3.

Now just load this by the webview:

public void onPageFinished(WebView view, String url) 
{       
    String loadPasswordJS = "$('input[name=\"username\"]').val('%@'); $('input[name=\"password\"]').val('%@'); $('.login').click();";
    view.loadUrl(loadPasswordJS);      
}
Community
  • 1
  • 1
Lepidopteron
  • 6,056
  • 5
  • 41
  • 53