Browser widget and javascript
Andreas Bergendal
andreas.bergendal at gmail.com
Sat Jun 28 11:14:37 EDT 2025
Certainly!
1) put ”liveCode.MyCommand(T.length);" at the end of your JavaScript code.
2) Add ”MyCommand” to the browser widget’s javascriptHandlers (either by script or in the field for it in the inspector)
3) Add the handler ”on MyCommand pT” to the browser’s script (or your card script or stack script).
4) Code whatever the handler should do with the value in pT.
”MyCommand” can of course be any name you want, as long as you are consequent in adding it to the browser widget’s javascriptHandlers and to a script that can catch it when the javascript sends it back to LiveCode.
WARNING: Do NOT use .length if the value of T is a number. LiveCode then instantly crashes with no chance to save your changes.
The JavaScript would return ”undefined”, and apparently neither LC9 nor LC10 can handle that at all. I should file a bug report on that.
/Andreas
> 28 juni 2025 kl. 16:07 skrev jbv via use-livecode <use-livecode at lists.runrev.com>:
>
> Hi list,
>
> When using a browser widget, I can get the whole code of a
> page displayed in the browser with :
> put the htmlText of widget "Browser" into myHtml
>
> I can also run chunks of javascript inside the browser,
> even if the code isn't there, for instance :
> do "var T=document.getElementsByClassName('xyz');alert(T.length);" in widget "Browser"
>
> But can I get some value generated via javascript back
> into the LC script and use it as a variable ?
> For instance in the above example, can I get the T.length
> value in a variable inside the LC script, after the chunk
> of js has ran ?
>
> Thank you in advance.
> jbv
More information about the use-livecode
mailing list