How does the new property Webviewer.WebViewString work?

7,595 views
Skip to first unread message
Assigned to jeffrey....@gmail.com by josmas...@gmail.com

Taifun

unread,
May 19, 2014, 5:17:23 PM5/19/14
to mitappinv...@googlegroups.com
in the new release there was introduced the new property Webviewer.WebViewString 
how can this be used?
sorry, the documentation does not help me very much ...
Taifun

from the release notes:
WebViewer: You can now communicate with the Javascript environment in the WebViewer by providing a string it can read

from the documentation
WebViewString
Gets the WebView's String, which is viewable through Javascript in the WebView as the window.AppInventor object


sebl...@gmail.com

unread,
May 20, 2014, 5:12:13 AM5/20/14
to mitappinv...@googlegroups.com
I'm also interested in knowing a bit better how this new feature works,
maybe it will be easy to pass values via javascript and web pages with web component, but how?
an example is really appreciated! thanks!

Hal Abelson

unread,
May 21, 2014, 8:10:39 AM5/21/14
to mitappinv...@googlegroups.com
You can use WebViewString to communicate values back and forth between your App, and the WebViewer.

In your App, you get and set the WebViewer.WebViewString properties.

In you webviewer, you open to a page that has Javascript that references the window.AppInventor object, using its getWebViewString() and setWebViewString(text) methods.

For example, if the WebView opens to a page that contains the Javascript

<script>
document.write("The value from the app is<br />" + window.AppInventor.getWebViewString());
</script>

and if you set the WebView.WebVewString property to "hello from my app", then the web page will show

The value from the app is
hello from my app.


Also, if the web page contains javascript the executes the command

windowAppInventor.setWebViewString("hello from Javascript")

then the value of the Webviewer.WebViewString property will be the text "hello from Javascript"

Taifun has done a lot of tricks that use the Web page title as a communication channel.  This is essentially the same thing, but
without needing to use the title.

We'll update the documentation to be more clear.

Does this explanation help?



SteveJG

unread,
May 21, 2014, 8:15:16 AM5/21/14
to mitappinv...@googlegroups.com
How about some blocks Hal?   Thanks.

-- Steve

M. Hossein Amerkashi

unread,
May 21, 2014, 9:22:56 AM5/21/14
to mitappinv...@googlegroups.com
Great update.

-Hossein.

Taifun

unread,
May 21, 2014, 9:44:39 AM5/21/14
to mitappinv...@googlegroups.com
Does this explanation help?
thank you Hal, this should help me to prepare an example soon
Taifun

Taifun

unread,
May 21, 2014, 11:04:16 AM5/21/14
to mitappinv...@googlegroups.com
a basic example how to use this can now be found here http://puravidaapps.com/snippets.php#2webviewstring
Thank you Hal! This offers some possibilities!
Taifun

Hal Abelson

unread,
May 21, 2014, 12:48:20 PM5/21/14
to mitappinv...@googlegroups.com
Jeff deserves the credit, not me -- I just reported what he did.

Thanks for writing this up!!

By the way, then I create those Javascript pages, i use android file transfer to put them in a directory like /Temp/stuff.html
Then from the app, I use the URL file:///sdcard/Temp/stuff.html

That works both in developer mode and production mode, although it does leave junk in the file system that has to be deleted lateer


Abraham Getzler

unread,
May 21, 2014, 1:21:06 PM5/21/14
to mitappinv...@googlegroups.com
Good example Taifun.

The example sets a global true/false variable development but instead refers
to a hardwired true in the Screen1.Initialize URL choice step.

The if/then/else should query development.

ABG

Taifun

unread,
May 21, 2014, 2:10:57 PM5/21/14
to mitappinv...@googlegroups.com
thank you ABG, now fixed
Taifun

Taifun

unread,
May 23, 2014, 5:40:30 PM5/23/14
to mitappinv...@googlegroups.com
a probably more useful example is now available here
App Inventor and Dynamic Table Layout now using the new WebViewString property
Taifun
 

Marcus Luton

unread,
Apr 13, 2015, 5:30:57 PM4/13/15
to mitappinv...@googlegroups.com
Hal,
Say I wanted to send 2 paragraphs from a textbox in my app to an html page with the necessary Javascript, what is the limit of characters I can send without error?
Reply all
Reply to author
Forward
0 new messages