Programmatically generating HTML using AI2 and presenting it via Webviewer

396 views
Skip to first unread message

Jayanth Acharya

unread,
Sep 30, 2014, 11:47:12 AM9/30/14
to mitappinv...@googlegroups.com

Hi,

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...





Abraham Getzler

unread,
Sep 30, 2014, 2:18:26 PM9/30/14
to mitappinv...@googlegroups.com
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

http://puravidaapps.com/snippets.php#2webviewstring

ABG

Taifun

unread,
Sep 30, 2014, 9:56:28 PM9/30/14
to mitappinv...@googlegroups.com
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...
Taifun

Jayanth Acharya

unread,
Sep 30, 2014, 11:10:45 PM9/30/14
to mitappinv...@googlegroups.com
Thanks Taifun. 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.

Jayanth Acharya

unread,
Sep 30, 2014, 11:14:00 PM9/30/14
to mitappinv...@googlegroups.com
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.

Taifun

unread,
Oct 1, 2014, 10:10:18 AM10/1/14
to mitappinv...@googlegroups.com
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)
Taifun

Jayanth Acharya

unread,
Oct 1, 2014, 11:54:43 PM10/1/14
to mitappinv...@googlegroups.com
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 ?

Jayanth Acharya

unread,
Oct 3, 2014, 1:41:21 AM10/3/14
to mitappinv...@googlegroups.com
Will post the last bit as a separate question, and mark this one completed. Thanks again, Taifun.
Reply all
Reply to author
Forward
0 new messages