2017년 6월 11일 일요일

How does the new property Webviewer.WebViewString work?


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

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

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

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

--
How about some blocks Hal?   Thanks.

--
Great update.

.-- 
Does this explanation help?
thank you Hal, this should help me to prepare an example soon

--
a basic example how to use this can now be found here http://puravidaapps.com/snippets.php#2webviewstring
webviewstring.aia


Thank you Hal! This offers some possibilities!

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

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

--
thank you ABG, now fixed

--
a probably more useful example is now available here
App Inventor and Dynamic Table Layout now using the new WebViewString property

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

--

댓글 없음:

댓글 쓰기