2017년 6월 2일 금요일

Programmatically generating HTML using AI2 and presenting it via Webviewer


Is it possible to programmatically generate HTML via AI2 and feed it directly to the Webview for presentation via it ?
I cobbled together what should be a valid HTML by concatenating various string parts, and then passed it to WebViewer.WebViewString, hoping that it'd display.
The string is something like this:
<html><body><p><b>Topic1</b>Description1</p><p><b>Topic2</b>Description2</p></body></html>
which should display like:
Topic1 Description1
Topic2 Description2
But, what I actually get in the WebView is a white canvas, nothing else. Snippet follows...


--
That WebViewString is meant to be used within a web page, not as the entire page.
Here's an example ...

http://puravidaapps.com/table.php
yes you can, see this App Inventor Classic example https://puravidaapps.com/label.php
alternatively create your HTML, store it with the FIle component in a directory of your SD card and display it...

--
In your 'Label' example, it says:

During first run of the app some files are downloaded to the SD card, which are used for this solution. The files used are 1. the jquery library, 2. the label.html file itself and 3. the App Inventor logo.

Wondering if, instead of 'downloading' the above files could be 'bundled' as 'assets', since I want my app to be usable by people using phones in 'offline/internet-disconnected' mode as well ? Would that work ?

And the key magic power is this urlencode and urldecode function... until I read through the HTML I was wondering why is jquery needed at all !! Now, I think I understand the WebViewString's role much better.

--
Thanks a lot Abraham, for pointing out the relevant parts. The 2nd URL explaining webviewstring answers the question to Taifun, so indeed, HTML file (& jquery or other js scripts, .css etc.) can be stored in assets folder.

--
Wondering if, instead of 'downloading' the above files could be 'bundled' as 'assets', since I want my app to be usable by people using phones in 'offline/internet-disconnected' mode as well ? Would that work ?
yes, but you will have to use the WebViewString property to pass values to the html then (this was not possible in App Inventor Classic)

--
Thanks is excellent. Is there anyway to simulate the AI2 webviewer to JS-in-HTML communication & vice-versa in a regular browser, just to test out the HTML+JS on a regular browser first ?

--
Will post the last bit as a separate question, and mark this one completed. Thanks again. 

--

댓글 없음:

댓글 쓰기