Page 1 of 1

Calling JavaScript RETURN function in LC Browser

Posted: Wed Apr 25, 2012 1:19 am
by BarrySumpter
This works the fist time the ControlDo execute firest.
But on second execute it stalls n returns "error"

If anyone has a thought could you please let us know?



Code: Select all

<html>
<head>
<script type="text/javascript">

function myfunction(txt)
{
alert(txt);
}

function myfunction2()
{
alert('Who Dat Be?');
}

function calculate(a,b,c) {
	d = (a+b) * c;
	return d;
}

</script>
</head>
<body>

<form>
<input type="button" onclick="myfunction('Hello')" value="Call function">
</form>

<p>By pressing the button above, a function will be called with "Hello" as a parameter. The function will alert the parameter.</p>

</body>
</html>

Code: Select all

on doCallBrowserFunction
   
   --MobileControlDo sBrowserId, "execute", "myfunction('sup dude!')"  
   --MobileControlDo sBrowserId, "execute", "myfunction2()"    
   MobileControlDo sBrowserId, "execute", "result=calculate(4,5,9)"    
   
   answer the result
   
end doCallBrowserFunction

Re: Calling JavaScript RETURN function in LC Browser

Posted: Wed Apr 25, 2012 1:42 am
by sturgis
With this very simple script embedded in a web page I can use mobilecontroldo sBrowserId, "execute", "getRandom();"
and as you say, when it works it does what its supposed to. the result contains .. well.. the result. Sometimes it will work 10 or 12 times in a row for me then for some reason it will fail with a long 10 to 12 second lock after which the result contains "error." Other times it fails on the first or second try.

Code: Select all

<script type="text/javascript">

function getRandom() {
return Math.floor(Math.random()*11)
}

</script>
It doesn't seem to matter WHAT is being returned. I even just had the function return the same string every time ("Hello") with the same issues. It works then it doesn't. Reloading the same page sometimes makes it work again, sometimes not.

Has anyone tried this on IOS, and does it work correctly there? I'm thinking there is something up with the android version of mobilecontroldo execute. My other thought is maybe there is something going on with the mobile browser control itself, but have seen javascripts working flawlessly in the browser instance itself so am leaning towards the former as the most likely.

Any suggestions to fix this/get around this would be very welcome.

Re: Calling JavaScript RETURN function in LC Browser

Posted: Wed Apr 25, 2012 1:52 am
by BarrySumpter
Trying this now:

Code: Select all

   select group "Browser"
   
   copy group "Browser" to this card
   set the name of it to "Browser2"
   
   if exists(group "Browser2") then
      answer "Browser2 exists!"
   else
      answer "Nope! Browser2 DOES NOT exist!"
   end if
   
   
   
   MobileControlDo "Browser2", "execute", "myfunction('sup dude!')"    
   MobileControlDo "Browser2", "execute", "myfunction2()"     
   MobileControlDo "Browser2", "execute", "calculate(4,5,9)"    

Doh! Sooo close. But Nope! Doesn't work.
Tried all kinds of variations.

Re: Calling JavaScript RETURN function in LC Browser

Posted: Mon Jul 17, 2017 10:03 am
by Saman Sjr.
it still happen this day..... :cry:

LC 8.1.5
Windows 7 64bit
Android 5.1.1
SDK 25.2.5
JDK 1.8.0