Skip to content Skip to sidebar Skip to footer

Using LoadUrl To Run Javascript Loads Different Page

We have an app that uses a form for oauth, just for dev purposes I want to eliminate typing in the user name and password so I added some code like this for when the page finishes

Solution 1:

If you look at a tool look Squirt it does an anonymous function call. So I am not that versed in javascript, but that anonymous call seems to be the key in that the browser sees it as the current page is making the call itself. So try this roughly:

mWebView.loadUrl("javascript:(function(){document.getElementById('UserName').value='" + txtUser.getText()+"';})()");

Solution 2:

I faced a similar issue and since I couldn't find a proper solution, I used the following hack -

  1. Fetch the html source text.
  2. Replace </body> tag with </body><script>YOUR JS CODE</script>
  3. webview.loadDataWithBaseURL(url, editedString, "text/html", "UTF-8", null);

Sorry for the hacky solution, but in case you can't find a solution, this could help :)


Post a Comment for "Using LoadUrl To Run Javascript Loads Different Page"