Reputation: 71850
Is there a way to get the HTML in a webview in an Android app? I would prefer this to getting the HTML via a simple resource download, especially if I can get HTML generated by JavaScript.
For example if I wanted a list of all URLs in a random HTML document accessible to my android application, including web apps such as gmail, how would I go about it?
The android documentation warns about letting JavaScript access the application, but I was thinking maybe a solution would be, if at all possible, to inject some JavaScript into the webpage which then communicates with my application in a hopefully safe way (via message passing or something through an iframe on a site that I control the javascript on or something similar).
Any one have any ideas?
Upvotes: 2
Views: 7185
Reputation: 594
a = (WebView) findViewById(R.id.web);
a.loadUrl("javascript:(function() { " +
"document.getElementById('inputID').value='"+EditText.getText()+"'; " +
"document.getElementById('inputID').value='"+EditText.getText()+"'; " +
"})()");
a.loadUrl("javascript:(function() {IWBUTTON1_onclick(false);})()");
Upvotes: 0
Reputation: 1006779
Is there a way to get the HTML in a webview in an Android app?
Not easily. javascript:
URLs work, and addJavascriptInterface()
allows you to set up callbacks that the Javascript can call. You may be able to create a snippet of Javascript loaded by a javascript:
URL that obtains your DOM, or walks your list of links, or something, sending the results back to you via the callback object you registered via addJavascriptInterface()
.
Upvotes: 2