do in widget (execute javascript in browser widget) - possible to get result?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
rodneyt
Posts: 128
Joined: Wed Oct 17, 2018 7:32 am

do in widget (execute javascript in browser widget) - possible to get result?

Post by rodneyt » Wed Oct 17, 2018 10:36 am

Hi everyone,

The do in widget command allows one to execute a javascript in the browser widget. Is there any way to get a result back? The conventional "do" command has a result but it seems the widget variant doesn't? Seems like a major omission?

~ Rodney

rodneyt
Posts: 128
Joined: Wed Oct 17, 2018 7:32 am

Re: do in widget (execute javascript in browser widget) - possible to get result?

Post by rodneyt » Wed Oct 17, 2018 11:11 pm

OK so here's the correct way to do this:

on preopenstack
set the javascriptHandlers of widget "ob3" to "jscallback"
end preopenstack

on test
local tJS
put "var myLoc;"&return&"myLoc=window.location.href;"&return&"liveCode.jscallback('location', myLoc);" into tJS
do tJS in widget "ob3"
end test

on jscallback pMessage,pValue
put "jscallback:" && pMessage & ":" && pValue
end jscallback

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: do in widget (execute javascript in browser widget) - possible to get result?

Post by [-hh] » Thu Oct 18, 2018 7:56 am

Hi. Welcome to the forum.

You don't have to "beautify" the javaScript. This would be enough:

Code: Select all

on test
   do "liveCode.jscallback('location',location.href)" in widget "ob3"
end test
shiftLock happens

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”