My app features a WebView where a local HTML page is loaded.
The page has
<span id="page752" epub:type="pagebreak">752</span>
somewhere embedded in text.
I get the element with id="page752" by means of getElementById function, then I call
element.scrollIntoView(true);
but it doesn't work, that is, no scroll is performed.
Note that the element text ("725") is not displayed in the WebView. Maybe this is related to the scroll not being performed.
How to make the span able to scrollIntoView?
Related
I have attached screenshots for web and app.
In web
Inside textview
Html.fromHtml() isn't supporting all HTML tags, check out supported list in HERE and THIS SO topic. its very basic implementation which doesn't supported e.g. nested <span tags (looks like) - closing tag </span> is closing ALL opened previously spans, not only last one (so your red background breaks after first span-styled letter, when orange-coloring-span is closed)
if you want full support of HTML content - use WebView and loadData method
I have a webView that loads a page. How do I copy all visible text on the webView? I don't want the innerHTML. I want the visible text. In other words, I want the same text that can be achieved by "selecting all" and copying.
Use a HTML parser which can give you nodes under your body element and keep aggregating text present inside each node. You could use this https://jsoup.org/
as a parser, it is quite established.
In my application (target 4.0), I have a chunk of HTML (which was pulled and parsed from a webpage) that I am displaying in a TextView. This HTML contains a large number of links (up to 100), most of which are relative, but some are absolute. I want the user to be able to click these relative urls URLs to launch a web browser.
How can I do this without going through the HTML and changing the URLs? Can I tap into a link click event?
You have to set a WebViewClient to your WebView and override shouldOverrideUrlLoading (and perhaps onLoadResource too).
You can match URL (and other patterns) using Linkifyand you can parse your content to use <a> tags like this:
Android Make hyperlinks in textview clickable
In other words, you need the href to contain a fully qualified URL, but you can still display the relative URL to the user.
No client URL works without full qualification, so you need to give the client a context. But this allows you to display relative URL's to the user.
I have a web page with about 150 HTML <a name="blah"></a> elements, plus 26 more that group these by letter, like <a name="lettera"></a>.
The page passes W3C HTML validation and renders and operates correctly in desktop browsers. Trying two different Android browsers and an emulator, the letter index does not work. When any letter is selected, the page only moves to the lettera tag. The location bar correctly shows <site>page.htm#letterx as the current location, but the display has not moved.
Other pages on the same site with a smaller number of name tags work correctly. I found one web reference saying that some browsers did not like to see two name tags in a row and suggesting placing the nonsense tag in between them to break them up, but this did not help. Any suggestions?
Answering my own question in case it helps someone else someday, it appears there needs to be actual renderable content between two successive name tags for the android browser (a comment alone didn't do it). When I added some all worked as intended.
Okay noob of the year question.
I have a website, which has several div. and one of those div I would like to put as the front end of an android app.
I.E, I have this div id
I want to put that entire element as the android application. Of course add buttons for it for various items, but right now that is my main obsticle.
I dont want to hard code the page into the android application, becuase of course that element changes.
Thank you in advance.
You could use a WebView to display a Website inside your application. See this article. If you want to display only one div of a website, you could move this div to another page. This should be the easiest method to achieve your goal.
BTW: There are no stupid questions ;-)
One option would be to code your site so that this DIV has a unique ID assigned to it. You could then download all of the HTML from your site into a string in your app, parse out this individual div you want (by finding the unique ID) and save it in a string named, say, html. Next you can place this DIV inside of a webview using webView.loadData(html, mimeType, encoding); where "html" is a string containing the div you extracted. So long as that DIV has content that has absolute paths to resources (images/links), it should load and display your content properly