Any success with iPhoneControlDo "execute" for scripts?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Any success with iPhoneControlDo "execute" for scripts?
Has anyone successfully used
iphoneControlDo sBrowserId, "execute", pScript
to run some javascript in an embedded browser control (UIWebView)?
If so, then how? i.e. what format should the script be in?
Are there examples somewhere?
Thanks for any pointers!
cheers
Alan
iphoneControlDo sBrowserId, "execute", pScript
to run some javascript in an embedded browser control (UIWebView)?
If so, then how? i.e. what format should the script be in?
Are there examples somewhere?
Thanks for any pointers!
cheers
Alan
Re: Any success with iPhoneControlDo "execute" for scripts?
I have had some success, but some challenges.. (assumes that the browser gMobBrowserID has already been created like
iphoneControlCreate "browser"
put the result into gMobBrowserID
This works on iOs:
put "alert('This is a message from the script');" into theFirstScript
iphoneControlDo gMobBrowserID, "execute", theFirstScript
also can do more than one line of JavaScript
put "alert('This is a message from the script');alert('This is another message from the script');" into theFirstScript
iphoneControlDo gMobBrowserID, "execute", theFirstScript
so I can execute multiple lines - even place the lines in a field for easier editing and visibility. (i.e. then "put field scriptData into theFirstScript")
BUT I can't get other simple things to work
alert(document.title);
will fail, with no error message in "the result"
In fact, if I have a field like
alert("This is a debugging message2");
alert("This is a debugging message3");
alert(document.title);
I don't get the first 2 alerts either - the whole statement fails
I find that these things (e.g. alert(document.title);) DO work on my mac, using get revBrowserExecuteScript(tBrowserId, theScript)
very frustrating....
I have tried using backslashes - doesn't work
For the lines above that do work, it seems to work with single quotes or double quotes on ios. They can have returns separating lines, in a field, or not...
also
according to Apple, "..JavaScript execution time is limited to 10 seconds .."
I need this to work for a project, so I will continue looking into it
I will try to post a test stack later today
r
iphoneControlCreate "browser"
put the result into gMobBrowserID
This works on iOs:
put "alert('This is a message from the script');" into theFirstScript
iphoneControlDo gMobBrowserID, "execute", theFirstScript
also can do more than one line of JavaScript
put "alert('This is a message from the script');alert('This is another message from the script');" into theFirstScript
iphoneControlDo gMobBrowserID, "execute", theFirstScript
so I can execute multiple lines - even place the lines in a field for easier editing and visibility. (i.e. then "put field scriptData into theFirstScript")
BUT I can't get other simple things to work
alert(document.title);
will fail, with no error message in "the result"
In fact, if I have a field like
alert("This is a debugging message2");
alert("This is a debugging message3");
alert(document.title);
I don't get the first 2 alerts either - the whole statement fails
I find that these things (e.g. alert(document.title);) DO work on my mac, using get revBrowserExecuteScript(tBrowserId, theScript)
very frustrating....
I have tried using backslashes - doesn't work
For the lines above that do work, it seems to work with single quotes or double quotes on ios. They can have returns separating lines, in a field, or not...
also
according to Apple, "..JavaScript execution time is limited to 10 seconds .."
I need this to work for a project, so I will continue looking into it
I will try to post a test stack later today
r
Re: Any success with iPhoneControlDo "execute" for scripts?
Hi there
I did have success with this, but I haven't been using stuff like "document.title".. What I did have success with was calling Javascript functions that are in my web page from LiveCode. So basically the same as you but it has (so far) been enough for me.
For returning values to my app I attach them to the end of my URL from inside the Javascript function using
window.location = "#?returnVal="&myReturnVal
and then catch this in browserLoadRequest and handle it if necessary.
Hope this helps.
I did have success with this, but I haven't been using stuff like "document.title".. What I did have success with was calling Javascript functions that are in my web page from LiveCode. So basically the same as you but it has (so far) been enough for me.
For returning values to my app I attach them to the end of my URL from inside the Javascript function using
window.location = "#?returnVal="&myReturnVal
and then catch this in browserLoadRequest and handle it if necessary.
Hope this helps.

Re: Any success with iPhoneControlDo "execute" for scripts?
Hi Strongbow
Thanks for the feedback. Based on this forum, the live code Developer mailing list and support feedback, you and I are among the four people in the world trying to do this stuff.
Surprising, as I think the internet is going to be BIG
, and Apple too..
I did post to another part of the forum, re "..you cannot exchange data in real time with JS in IOS browser.."
http://forums.runrev.com/viewtopic.php? ... 091#p52091
Calling a Javascript in the page is a good idea, and will work in some cases where I have control/input to the page, but for what I am trying to do that is not always a solution.
I will keep digging
btw I am Australian, living in California - good to see New Zealand, Australia active in these things
regards
Thanks for the feedback. Based on this forum, the live code Developer mailing list and support feedback, you and I are among the four people in the world trying to do this stuff.

Surprising, as I think the internet is going to be BIG

I did post to another part of the forum, re "..you cannot exchange data in real time with JS in IOS browser.."
http://forums.runrev.com/viewtopic.php? ... 091#p52091
Calling a Javascript in the page is a good idea, and will work in some cases where I have control/input to the page, but for what I am trying to do that is not always a solution.
I will keep digging
btw I am Australian, living in California - good to see New Zealand, Australia active in these things
regards
Re: Any success with iPhoneControlDo "execute" for scripts?
G'day there
Yup, as I have control over my page I can add functions etc as required. Also enables me to post stuff back to my LiveCode app that can then process it in "real-time"...
But, as you say, you have some other requirements. Haven't tried what you say so will be interested to see what you can come up with... will also let you know if I manage anything interesting.
Good luck in Cali - I'm a Kiwi in Germany... Drop in if you're over this way!
Yup, as I have control over my page I can add functions etc as required. Also enables me to post stuff back to my LiveCode app that can then process it in "real-time"...

Good luck in Cali - I'm a Kiwi in Germany... Drop in if you're over this way!

-
- Posts: 1201
- Joined: Sun Apr 24, 2011 2:17 am
Re: Any success with iPhoneControlDo "execute" for scripts?
Hi strongbow,
Any way I can get you to post a sample app on how you are doing this?
i.e. posting back to LC app for real time processing?
tia
Any way I can get you to post a sample app on how you are doing this?
i.e. posting back to LC app for real time processing?
tia
All my best,
Barry G. Sumpter
Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.
Barry G. Sumpter
Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.
Re: Any success with iPhoneControlDo "execute" for scripts?
Hi Barry
Well, the above bit explains one part of it:
To call a JS function from LC I just load a javascript function call into a variable and then call it using
where pBrowserId is the id of your iOS browser instance and pScript is the JS function, eg. computeDistance()
Inside that function, I would have the line:
or something similar - this adds that string to the URL to be loaded. And then you catch that inside LC by handling:
Here you would check if pURL contained the bits you added (i.e. returnVal=....) and if so, handle it inside LC.
I know this isn't that clear, probably a diagram of the process would be most understandable, but hope that it helps in some way.
cheers
Alan
Well, the above bit explains one part of it:
The actual URL that you load could be on a website or even a local html file with included javascript functions.For returning values to my app I attach them to the end of my URL from inside the Javascript function usingand then catch this in browserLoadRequest and handle it if necessary.Code: Select all
window.location = "#?returnVal="&myReturnVal
To call a JS function from LC I just load a javascript function call into a variable and then call it using
Code: Select all
iphoneControlDo pBrowserId, "execute", pScript
Inside that function, I would have the line:
Code: Select all
window.location = "#?returnVal="&myReturnVal
Code: Select all
on browserLoadRequest pUrl, pReason
I know this isn't that clear, probably a diagram of the process would be most understandable, but hope that it helps in some way.
cheers
Alan

-
- Posts: 1201
- Joined: Sun Apr 24, 2011 2:17 am
Re: Any success with iPhoneControlDo "execute" for scripts?
Hi Alan,
Many thanks for the reply.
Thanks for clarifying the logic behind this concept.
Where a picture is worth a thousand words,
a working sample app is worth a billion.
I'll know what to do when I get to the iOS version of my app.
Or when RR opens up the browser events for Android.
Thanks again.
Many thanks for the reply.
Thanks for clarifying the logic behind this concept.
Where a picture is worth a thousand words,
a working sample app is worth a billion.

I'll know what to do when I get to the iOS version of my app.
Or when RR opens up the browser events for Android.
Thanks again.
All my best,
Barry G. Sumpter
Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.
Barry G. Sumpter
Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.
-
- Posts: 83
- Joined: Mon Oct 31, 2011 5:28 am
Re: Any success with iPhoneControlDo "execute" for scripts?
just thought I'd post that I found this thread very useful, using the technique to trigger animations created using Hype (HTML 5 editor). So thanks for the post.