I have a WebView with some web page in it. Now I want to retrieve complete HTML contents of what is inside the WebView.
I use loadUrl("javascript:...") and WebView's javascript interface feature to retrieve this HTML using something like this:
document.getElementsByTagName('html')[0].innerHTML / outerHTML
document.documentElement.outerHTML
...
In each case I receive partial HTML contents - exactly first 10000 characters! So my question is - how do I get complete HTML content? Is it device-specific and, maybe there are workarounds?
Btw, web pages are created dynamically with javascript - I can't simply download the file from server.
Also, I tried printing HTML contents in javascript with console.log and found exactly the same behavior.
Thanks in advance!
My mistake - it was not related to javascript, neither had to do with specific device I tested on.
So, in short, any of those js properties work correctly.
Related
I have 20+ html pages stored in asset folder in android. These html pages belongs to my website. And all the pages are at different depth in asset folder. (I am writing after 3-4 hours of searching on Google, SO, etc. but no clue! And I am new to android, so need help..)
Now when user types something related to the html pages in edittextview, then that bunch of words will be split in array and then all the words will be matched from all the html pages.
And if most of the words are matched then, user can see that particular webpage (html page) in webview.
How can I achieve that?
I did as said in http://www.monocube.com/2011/02/08/android-tutorial-html-file-in-webview/ but no clue!
And even did https://stackoverflow.com/a/24670620/5738881 but not what I am in need of!
Thanks.
A solution to this is too complicated to write here, but you will have to include some javascript with the HTML that will do the manipulation of the DOM. You have no access to the DOM from Java.
What you can do is call a javascript method in a page loaded into a WebView by loading a javascript url with a function call into some js entry point into the WebView via loadUrl. You can call back into Java from javascript using a mechanism that will require some study. Start by looking at addJavascriptInterface.
I have an app that has a web-view which has a basic web-form that has a few fields and a submit button. I would like to figure out in my app if the form has any input in any of the fields. I cannot change the form from the server side, and I can't be certain much about the fields (ids / names in the html).
In iOS we accomplish this with an interesting process of pulling all the html out when loading the form, and comparing it to the html at any given point, if they don't match, the user must have entered something into a field. I believe we were able to get the html by injecting and running some javascript into the web-view. I'm not sure exactly how to approach the problem on android, or if android has any better tools to get whether a form has been edited.
Anybody have any ideas / pseudo-code how I can tell if a form has had input in any of the fields in a webview in android?
Unfortunately, there are no special form-related tools in Android WebView either. You can use the same approach as you have described for iOS.
A couple of links to get you started:
Read HTML content of webview widgets
Android Web-View : Inject local Javascript file to Remote Webpage
I am working on what amounts to a custom android web browser and need to work around a bug in XHR.
I'd like to use a javascript XHR wrapper that fixes the bug (I already have the fix).
How can I force this to be loaded on every page load before anything else is loaded, including scripts in the head?
Note that arbitrary web content which I do not control will be loaded into my webview, so I can't do anything like load my script from the html page. I need to do something like intercept the first script request in head and synchronously inject my script. I'm not sure if this exact approach is possible - just trying to provide an example of the sort of approach that would satisfy my requirements.
I'm open to a completely different approach - I just know how to fix it via a javascript wrapper.
The details of the bug that I need to fix are not important, but just in case anyone is curious, successful XMLHttpRequests for non-android_asset file urls leave status set to 0 and statusText to "". Since some frameworks that use XHR treat status!=200 and/or statusText!="OK" as an error, I need to override the default behavior and return status=200 and statusText="OK" for successful XMLHttpRequests for non-android_asset file urls.
Since someone recently upvoted this and no one else offered any input, I'll share what I ended up doing to address the problem, even though it does not really address my original question.
In my case, I am only loading local (that is, dynamic files that are copied locally prior to being loaded into the webview) html files which I have access to via the filesystem prior to loading them into the webview. Therefore, I have an opportunity to modify the file prior to loading them. Since I could not find a better approach, I simply insert a script tag as first child of head in order to ensure that XHR override happens before anything else.
Feel free to comment if you want more details - I will do my best to answer!
Let's say I have an HTML page which has CSS bound, all parsed from JSON data; is there a way to reproduce exactly ( with responsivity as well ) the same visualization in an android application with no webview ?
My goal is to have a html product that I can see also on an application, but with native elements.
EDIT
maybe this semplifies the situation: how to share HTML between mobile and web?
textview.setText(Html.fromHtml(HTML_STRING));
I have read the example for Rss Parsing from the ibm site.(http://www.ibm.com/developerworks/opensource/library/x-android/).
In this example,the rss are shown in a listview and then,if you press one announcement you can see it in the web browser of the device.How could i see them in the app,with no use of the device browser?
Thanks a lot
Create a layout with a WebView then load the URL from each "announcement" using WebView.loadUrl.
I'm a little confused but you seem to have answered your own question.
You say you don't want to use the web browser on the device but the example in your question doesn't use the browser. It does exactly what you're asking for.
The idea is that you download the html from the website and then use the parser to break it up into separate "announcements" and store them in list view items in your program.
I have done a bit of this type of thing myself in android. I used jsoup java library, which makes breaking the html into the bits you want to display really easy.
If you want some more help I can give you an example of an app I made that pulls movie times from google.com/movies as an example. here are links to the classes where I did the html download and parse:
ScreenScraper.java
HtmlParser.java