View Full Version : How To Refresh One Image?
James12513
Oct 11th 2007, 11:01 am
Could some one please tell me how I would refresh one image every time 2 minutes?
Can some please show me a source code, I've been trying for ages. :)
KatieK
Oct 11th 2007, 11:14 am
Hmmm... Will the image be the same file name? (And it's the server that changes the image?)
James12513
Oct 11th 2007, 11:29 am
Yes the image will be the same file name and the server will be the one changing the image.
le_gber
Oct 11th 2007, 3:02 pm
If it's the server that changes the images you cannot use javascript for that. You have to use a sheduled task or cron job.
Why not use javascript instead. Name your images image1.gif, image2.gif etc... and do something like
set timer;
count to 20 seconds;
if i < max image number
img.src = image[i].gif
add 1 to i
else
image src = image.gif
start over
or just create an animated gif that changes every 20 seconds
KatieK
Oct 11th 2007, 3:25 pm
This will do it. Just change both instances of "image.png" to whatever your image name will be.
First I set up a function that uses the DOM to specify the image. (The image would change onscreen if it were a different filename in the JS function.)
Then, in the body of the document, I set up a counter that calls the function every 180000 milliseconds, or every 2 minutes.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Test</title>
<script type="text/javascript">
function imgRefresh()
{ document.getElementById("changeMe").src = "image.png"; }
</script>
</head>
<body>
<img src="image.png" id="changeMe" />
<script type="text/javascript">
setInterval('imgRefresh()', 180000);
</script>
</body>
</html>
James12513
Oct 12th 2007, 8:13 am
Thank you le_gber and KatieK, I'm going to try out those methods now. :)
I'm not entirely sure my server changes the images, I don't think so.
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.