how to get data from widget browser

Mike Bonner bonnmike at gmail.com
Wed May 25 19:20:47 CEST 2016


Actually not that complicated (I think).  My javascript understanding is
pretty limited but..

As long as you have a defined handler in livecode, you can do interesting
things.  If there is a function in your page that returns dataA and another
that returns dataB, you would just have to build up your script wrapped in
a liveCode.whateverHandler() call.
Something like
do "liveCode.whateverHandler(dataAFunction(),dataBFunction())" Then use
paramcount() in livecode to do your processing.  Not that much different
from the old way (call script) except you use the registered handler to
wrap the function (or functions) being called. whateverHandler could be
seen as a callback, so when a call is made to the widget, include some type
of identifying param, and have it returned along with your data if
necessary.

Some very interesting possibilities, like a callback loop.  Make a request,
the widget responds firing an event, which makes a request.. One could make
a browser widget clock this way, or move things around in the widget or..

I could lose so much time on this!


On Wed, May 25, 2016 at 9:13 AM, Jacques Hausser <Jacques.Hausser at unil.ch>
wrote:

> mmm… yes, I’ll try something in that direction (except that in the real
> case it will be a bit more complicated). A pity this beautiful widget has
> nothing more straightforward to pick data from webpages (but perhaps it
> has, well hidden).
> Thank you anyway, Mike !
>
> Jacques
>
> > Le 25 mai 2016 à 16:03, Mike Bonner <bonnmike at gmail.com> a écrit :
> >
> > Just experimented with things and found a way that works.  There is
> > probably a more direct way using do "script" in browser directly, but I
> > haven't figured that out yet.  In the interim..
> >
> > I put this into the htmltext of a widget
> >
> >
> > <html>
> > <body>
> > Hi!
> > <script>
> > function testit () {
> > liveCode.myJSHandler("myMessage",12345);
> > }
> > </script>
> > </body></html>
> >
> > It defines a function testit, that then defines an inline function using
> > the liveCode object, handler named myJSHandler
> >
> > In my livecode script I have this
> >
> >
> > command setHandlers
> >   set the javascriptHandlers of widget 1 to "myJSHandler" -- tells the
> > widget that when the livecode.myJSHandler() function is able to execute
> the
> > myJSHandler handler in lc
> > end setHandlers
> >
> > command myJSHandler pMessage,pVar
> >   put pMessage & cr & pVar -- A simple example with returned data
> > end myJSHandler
> >
> >
> > To see it in action, I executed in the message box..
> > do "testit()" in widget 1 -- my only widget
> > The function ran, called the livecode handler myJSHandler passing the 2
> > values in, and the livecode handler put them into the message box as
> > expected.
> >
> > It should be possible to write a generic handler in lc to receive data,
> > then add it to the javascripthandlerlist for that widget.  You shouldn't
> > even have to pre-define your javascript as part of your htmltext, you
> > should be able to execute on the fly.
> >
> > do "liveCode.myJSHandler('this is a message',8*8)"in widget 1
> >
> > Which will call the livecode myJSHandler  from javascript in the widget
> > after evaluating the 8*8
> >
> >
> >
> > On Wed, May 25, 2016 at 6:51 AM, Jacques Hausser <
> Jacques.Hausser at unil.ch>
> > wrote:
> >
> >> Sorry to come back with this question. I have a widget browser defined
> by
> >> a html file. It works fine. But I’m trying to get the result returned by
> >> some functions in the html, that is, to find an equivalent of the
> >> revBrowserCallScript function, which was working well with the pre-8
> >> versions of my stack. I tried “do ‘script’ in widget” with several
> >> ‘scripts’, without success, I cannot find where the returned value is
> >> hidden (I must confess I’m a featherless sparrow rather than an eagle in
> >> javascript).
> >> Thank you in advance
> >>
> >> Jacques
> >>
> >> _______________________________________________
> >> use-livecode mailing list
> >> use-livecode at lists.runrev.com
> >> Please visit this url to subscribe, unsubscribe and manage your
> >> subscription preferences:
> >> http://lists.runrev.com/mailman/listinfo/use-livecode
> > _______________________________________________
> > use-livecode mailing list
> > use-livecode at lists.runrev.com
> > Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> > http://lists.runrev.com/mailman/listinfo/use-livecode
>
> ******************************************
> Prof. Jacques Hausser
> Department of Ecology and Evolution
> Biophore / Sorge
> University of Lausanne
> CH 1015 Lausanne
> please use my private address:
> 6 route de Burtigny
> CH-1269 Bassins
> tel:    ++ 41 22 366 19 40
> mobile: ++ 41 79 757 05 24
> E-Mail: jacques.hausser at unil.ch
> *******************************************
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


More information about the use-livecode mailing list