|
-
March 29th, 2011, 08:11 PM
#5
Re: Help with JavaScript Code
Sorry about if you don't understand.. me explain it a little better.
I have a Image on a page:
Code:
<img src="http://123.123.123.123/camera.get?image=1" alt="web image" id="img0" />
I need to refresh that image every second (as it will change - it's a camera).
however, I need to refresh that image without displaying the old image thats why I am adding a random number to the end of the image. (so it Forces a new image)
however, what I am facing is that when I refresh the image with my code
Code:
function reloadIt1()
{
var image1 = (document.getElementById("img0").src);
image1 = image1.split('?', 2);
if (document.getElementById("img0"))
{
document.getElementById("img0").src = (image1[0]) +"?"+ Math.random();
setTimeout("reloadIt1()", 1000);
;
}
else
{
setTimeout("reloadIt1()", 1000);
}
}
{
}
It replaces the image (just like it's meant to, with a random number) however the URL of the image source is just getting bigger and bigger as it keeps adding a random number onto the end without replacing the random number.
that is what I am needing help with.
I need to refresh the image with a new random number.
What I want to happen:
Orignal URL = http://123.123.123.123/camera.get?image=1
new URL = http://123.123.123.123/camera.get?image=1?0.5694605531825758
1 second later, URL = http://123.123.123.123/camera.get?image=1?0.2356246538895740
2 second later, URL = http://123.123.123.123/camera.get?image=1?0.4336847536855723
etc...
at the minute its doing the following:
Orignal URL = http://123.123.123.123/camera.get?image=1
new URL = http://123.123.123.123/camera.get?image=1?0.5694605531825758
1 second later, URL = http://123.123.123.123/camera.get?image=1?0.5694605531825758?0.2356246538895740
2 second later, URL = http://123.123.123.123/camera.get?image=1?0.5694605531825758?0.2356246538895740?0.4336847536855723
etc...
I can't seem to work out how to replace the old random number with a new random number.
Got any ideas now ?
Hope this helps now..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|