How to get html content from a webview?

Can a WebView access the content inside it, without having to modify the source HTML?

  • This feature would be useful for things like pre-populating forms. Something like what plugins for Firefox or Chrome do, when manipulating the DOM of the content they load.

  • Answer:

    You can execute arbitrary JavaScript using WebView.loadUrl with JavaScript URLs, and thus access content, alter it, etc. For example, let's say you wanted to set the value of a user's name on the web page being shown by your WebView. You know that the name field has ID='username'. So you could do something like: myWebView.loadUrl("javascript:document.getElementById('username').value='Miguel'");

Michael Galpin at Quora Visit the source

Was this solution helpful to you?

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.