Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
New Developer
NewtownGuy
Posts: 22
Registered: ‎05-14-2009
My Device: Not Specified

JavaScript runs once but won't continually update

Hello,

 

I'm a total newbie to BB. I'm trying to update a

JPEG image multiple times per second. I'm using the 8830 simultator and the MDS simulator. My JavaScript runs fine on IE and FF. But it only runs the first time through on the simulators, and stops after that instead of updating periodically.

 

I'm using this code in my html page, which calls a php page to fetch each image:

 

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">

<html>
<head>

<title>Viewer</title>

<meta name="viewport" content="width=340">
<script language=JavaScript">
function LoadImage(){
document.getElementById('myImg').src='getframe.php?rnd='+Math.random();
}
</script>
</head>
<body>
<img src="getframe.php" id="myImg" />
<script language="JavaScript">
setInterval('LoadImage()', 200);
</script>
</body>

 

</html>

 

 

Can someone tell me how to make this script run continuously ?

 

Thank you.

 

 

Please use plain text.
Guru I
Xandrex
Posts: 18,403
Registered: ‎07-29-2008
My Device: Z30, Playbook, 9320BES
My Carrier: B&You _ SFR

Re: JavaScript runs once but won't continually update

hello,

for OS prior to 4.6, the DOM model is not dynamic, meaning javascript works only the first time.

your device has OS 4.5 or less.



The search box on top-right of this page is your true friend, and the public Knowledge Base too:
Please use plain text.
New Developer
NewtownGuy
Posts: 22
Registered: ‎05-14-2009
My Device: Not Specified

Re: JavaScript runs once but won't continually update

But what is the solution or workaround ? Does the customer (user of 8830) need to get an OS or JavaScript update, or does he need to get a more recent BB ?

 

Am I using the right JavaScript code to rerun the script every X milliseconds ? Or is using <meta refresh> with one second the best I can do ? Is there a different syntax or function that I need to use for BB to rerun the script every X milliseconds ?

 

Thank you.

 

 

Please use plain text.
New Developer
NewtownGuy
Posts: 22
Registered: ‎05-14-2009
My Device: Not Specified

Re: JavaScript runs once but won't continually update

I loaded the simulator for a more-recent model, the 9530, but it won't continually update the image either. As you can see above, I'm using this JavaScript code:

 

setInterval(xxx);

 

to periodically get a new image, every 200 milliseconds in the code above.

 

Is this the right code to use on a BB ? It works fine on IE and FF.

 

Thank you.

 

Please use plain text.
New Developer
NewtownGuy
Posts: 22
Registered: ‎05-14-2009
My Device: Not Specified

Re: JavaScript runs once but won't continually update

Don't any millisecond-level timers work on the BB ???

 

I changed my code (see my original post) to use onload setTimeout, and I also put setTimeout in the function that is called. Again, it works fine on IE and FF, but it only runs once on the 9530 simulator.

 

How do I get timers that can give me 200 mS or less intervals in JavaScript to work on BB ?

 

Thank you.

 

 

Please use plain text.
New Developer
NewtownGuy
Posts: 22
Registered: ‎05-14-2009
My Device: Not Specified

Re: JavaScript runs once but won't continually update

How do I turn on JavaScript on the BB ? I don't see any way to check or change the browser's settings.

 

I set up a test page, and it reported that either my browser does not support JavaScript, or I have JavaScript turned off.

 

Here's the test code I used:

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head><title>simple page</title></head>
  <body>
    <script type="text/javascript">
      document.write('Hello World!');
    </script>
    <noscript>
      <p>Your browser either does not support JavaScript, or you have JavaScript turned off.</p>
    </noscript>
  </body>
</html>

 

Please use plain text.
New Developer
NewtownGuy
Posts: 22
Registered: ‎05-14-2009
My Device: Not Specified

Re: JavaScript runs once but won't continually update

I'm going craxy trying to solve this problem... 

 

I found out how to enable JavaScript in Browser options. I've now turned it on in both the 8830 and 9530 simulators. But neither one of them will update the image.

 

Is there any JavaScript timer support in BB ??? How do I use it ? If not, what's a workaround ? Can someone correct my original script so I can test it ?

 

Thank you.

 

 

Please use plain text.
Guru I
Xandrex
Posts: 18,403
Registered: ‎07-29-2008
My Device: Z30, Playbook, 9320BES
My Carrier: B&You _ SFR

Re: JavaScript runs once but won't continually update


NewtownGuy wrote:

How do I turn on JavaScript on the BB ? I don't see any way to check or change the browser's settings.





home screen >> browser >> options >> browser configuration

then you have to edit the configuration for each browser you want.

then to test your page, you have to load it using the correct browser.



The search box on top-right of this page is your true friend, and the public Knowledge Base too:
Please use plain text.
New Developer
NewtownGuy
Posts: 22
Registered: ‎05-14-2009
My Device: Not Specified

Re: JavaScript runs once but won't continually update

I have been able to modify the browser settings, thank you, for both simulators. I now get the desired 'Hello World' response from both of them that says JavaScript is now active. However, there's no improvement in my script. My script still runs only once and then stops. So the timer in JavaScript is still not working. How do I fix the timer ?

 

 

Please use plain text.
Guru I
Xandrex
Posts: 18,403
Registered: ‎07-29-2008
My Device: Z30, Playbook, 9320BES
My Carrier: B&You _ SFR

Re: JavaScript runs once but won't continually update

you are doing too much in your code. You need to simplify each step in order to understand what is wrong.

do not use the setInterval() method.
do not use a Math.ramdom() method.
instead of calling the LoadImage() function, just paste its content.
don't use an URL that computes an image on serverside. Use a fixed URL.

then you can debug more easily.



The search box on top-right of this page is your true friend, and the public Knowledge Base too:
Please use plain text.