Update image at regular intervals

K

Karl E. Peterson

Hi --

I'm sure this is a FAQ, but I'm not seeming to hit the write google words. What's
"the simple way" to update an image, without refreshing the entire page, at regular
intervals? Just a little javascript, I would presume?

Thanks... Karl
 
K

Karl E. Peterson

Rob said:

Okay, that was pretty straight forward.

Any idea why this implementation "doesn't work"? <g>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
<script language="JavaScript">
<!-- Begin
function updateGraphics() {
var now = new Date();
document.form1.clock.value = now.getTime();
document.images['webcam'].src = 'images/911cam.jpg';
window.setTimeout('updateGraphics()', 1000);
}
// End -->
</script>
</head>

<body onLoad="updateGraphics()">

<form NAME="form1">
<p align="right"><input TYPE="text" NAME="clock" SIZE="30" VALUE></p>
</form>

<p align="right"><img name="webcam" border="0" src="images/911cam.jpg" width="160"
height="120"></p>

</body>
</html>

What happens is, the updateGraphics routine gets called once on page load/refresh,
and then once/second thereafter (as shown by the "clock" in form1). But the graphic
isn't getting reloaded. To make sure I'm seeing this right, I'm forcing a new
capture and Refresh does load the new graphic. Very puzzling.

Thanks... Karl
 
K

Karl E. Peterson

D'oh! Is the code below actually "working" but just not obviously so? I mean, I'm
telling it (or at least *wanting* to tell it!) to reload the image. The image file
itself is being updated, but it still has the same name. Are both IE and FF
"helping" me by caching that?

Thanks...

Rob said:

Okay, that was pretty straight forward.

Any idea why this implementation "doesn't work"? <g>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
<script language="JavaScript">
<!-- Begin
function updateGraphics() {
var now = new Date();
document.form1.clock.value = now.getTime();
document.images['webcam'].src = 'images/911cam.jpg';
window.setTimeout('updateGraphics()', 1000);
}
// End -->
</script>
</head>

<body onLoad="updateGraphics()">

<form NAME="form1">
<p align="right"><input TYPE="text" NAME="clock" SIZE="30" VALUE></p>
</form>

<p align="right"><img name="webcam" border="0" src="images/911cam.jpg" width="160"
height="120"></p>

</body>
</html>

What happens is, the updateGraphics routine gets called once on page load/refresh,
and then once/second thereafter (as shown by the "clock" in form1). But the
graphic isn't getting reloaded. To make sure I'm seeing this right, I'm forcing a
new capture and Refresh does load the new graphic. Very puzzling.

Thanks... Karl
 
K

Karl E. Peterson

Karl said:
D'oh! Is the code below actually "working" but just not obviously so? I mean,
I'm
telling it (or at least *wanting* to tell it!) to reload the image. The image
file
itself is being updated, but it still has the same name. Are both IE and FF
"helping" me by caching that?

Yep, that was it. I had neglected to append the random digits to the end, as your
example showed. Figured I had no need for them! Sheesh.... But, that tiny little
step is what tells the browser it needs to submit a new request. Live and learn,
huh?
 
R

Rob Giordano \(Crash\)

glad you got it sorted.
sorry I crashed and burned early yesterday :-(


--
~~~~~~~~~~~~~~~~~~
Rob Giordano
Microsoft MVP Expression
 
K

Karl E. Peterson

Rob said:
glad you got it sorted.
sorry I crashed and burned early yesterday :-(

Nah, you pointed at the exact solution. I just tried to be smarter than the
collective wisdom of the internet, and, well, you know where that gets a guy. <g>

Thanks again... Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top