how to push data from the webview.Execute into the main droidscript application's code

618 views
Skip to first unread message

Zenith Wogwugwu

unread,
Feb 13, 2016, 2:46:06 AM2/13/16
to DroidScript
Hi guys,

I'm new to driodscript and i find your work on building android apps awesome!

I'm writing my first app and my problem is i need to pass data from webview.Execute() to the main droidscript app.

I've tried declaring a global variable in the droid script app and setting the variable in the webview.Execute method. Like this

//////////////////////////////
Var data;

Function OnStart(){
//...

Web.Execute("data='blah'");

app.ShowPopup(data);
}

///////////////////////////////

I would highly appreciate your help

Chris

unread,
Feb 13, 2016, 9:40:47 AM2/13/16
to DroidScript
You must think about the scope of variables when using a webview.

Any variable inside the webview is contained only in that webview, and not available to your app, or the other way around.

Globals included.

You're example sets a variable in the webview, but it won't be available to your app.

a = 'Hello';
web.Execute('a = "'+a+'";');

For dynamic inputs, etc... there are many ways.... just remember scope.

If your webview is local (not a url) add:

<script src='file:///android_asset/app.js'></script>

Then you can use DS methods inside your webview, but most importantly, you can send vars back or run functions from your app.

Example... say you have a html button in your webview, you can use an onclick handler to run a function in your app.

onclick="app.Execute('myFunction()');"

Hope that helps :)

Zenith Wogwugwu

unread,
Feb 15, 2016, 12:58:58 PM2/15/16
to DroidScript
Thanks Chris, the app.Execute() method worked like a charm!
Reply all
Reply to author
Forward
0 new messages