JackTheRussel
Programmer
Hi.
I have tried to create javascript-code which would refresh images that are in my web-page.
I put images on site by using PHP. At the same time when I put images on my site, I put image-names on javascript-array.
Then I have tired to create code, which would refresh images.
// OK Here I put images on site. I get image-names from database. code is shortened:
Now I would need some help:
Now when images are in page, and image-names are in the js-array, I would need code, which would refresh images after 3 seconds.
I have tried code like this, but it doesn't work:
I have tried to use this code, which refresh just one image.
This code works:
I have tried to create javascript-code which would refresh images that are in my web-page.
I put images on site by using PHP. At the same time when I put images on my site, I put image-names on javascript-array.
Then I have tired to create code, which would refresh images.
// OK Here I put images on site. I get image-names from database. code is shortened:
Code:
for ($i = 0; $i < mysql_num_rows($query); $i++) {
echo "<img src='$record'><br><br>";
// Here I take image-names to the js-array
echo "<script type='text/javascript'>";
echo "imagenames[$i] = '$record';";
echo "</script>";
}
Now I would need some help:
Now when images are in page, and image-names are in the js-array, I would need code, which would refresh images after 3 seconds.
I have tried code like this, but it doesn't work:
Code:
<script language="javascript" type="text/javascript">
var t = 3;
for(i = 0; i < imagenames.length; i++){
"image"+i+"="+imagenames[i];
}
function Start() {
tmp = new Date();
tmp = "?"+tmp.getTime()
for(i = 0; i < imagenames.length; i++){
document.images["something"].src="image"+i+"="+imagenames[i]+tmp
}
setTimeout("Start()", t*1000)
}
Start();
</script>
I have tried to use this code, which refresh just one image.
This code works:
Code:
<IMG src="image_name.jpg" width="275" height="200" border="1" name="refresh">
<SCRIPT language="JavaScript" type="text/javascript">
<!--
var t = 120 // interval in seconds
image = "image_name.jpg" //name of the image
function Start() {
tmp = new Date();
tmp = "?"+tmp.getTime()
document.images["refresh"].src = image+tmp
setTimeout("Start()", t*1000)
}
Start();
// -->
</SCRIPT>