PDA

View Full Version : reloading an image



nobody
May 28th, 2003, 08:56 PM
Does anybody know how to refresh an image every 15 seeconds using javascript? It's the same pic.. but the pic changes cuz its from a webcam. Tell me if thats not specific enough

solid
May 30th, 2003, 05:55 PM
<script language="JavaScript">
<!--
var sURL = unescape(window.location.pathname);
function doLoad() {
setTimeout( "refresh()", 15000);
}

function refresh() {
window.location.href = sURL;
}
-->
</script>


Then stick this in your pages BODY tag:

onLoad="doLoad();"

Try that.

solid
May 30th, 2003, 05:56 PM
holy crap, my last post messed this thread up!

solid
May 30th, 2003, 05:56 PM
looks like my last post skrewed this topic up.

Alex
May 30th, 2003, 06:31 PM
whoa, that code messed up the forum lay out.

josh, try this

http://javascript.internet.com/miscellaneous/refresh.html

kirupa
May 30th, 2003, 06:39 PM
Not to worry solid; you forgot to close the script tag =)

Cheers!
Kirupa :thumb:

ahmed
May 30th, 2003, 07:17 PM
or you can just use a simple html meta tag:
<HEAD>
<meta http-equiv="Refresh" content="3; URL=index.html">
</HEAD>


[edit]

3 is the number of seconds (i guess)

nobody
May 31st, 2003, 12:45 PM
hey guys.. thanks a lot, but i dont want to refresh the whole page.. i just want to refresh a picture
is there a way to do that?
if not i could just keep loading it up through flash or something i guess

nobody
June 1st, 2003, 10:40 PM
beeeee------ump

abzoid
June 1st, 2003, 10:51 PM
The only way I know to do it is to use a frameset, where the frame for the cam image is almost the same size as the image. Use the meta refresh code that Ahmed posted on the page with the cam image.

That's how we did it for webcam sites back in the days before streaming video.

nobody
June 2nd, 2003, 04:37 PM
lol sounds good.. so I'll slap up the ol' iFrame and be stylin

abzoid
June 2nd, 2003, 06:38 PM
Let me know how it works with the iframe. We didn't have that option back then since iframes didn't work with Netscape, and at the time Netscape had about 70% of the market.

nobody
June 2nd, 2003, 06:47 PM
I'm probably gonna try tomorrow or wednesday since my freakin camera decided to just out of nowhere break and i have no idea whats wrong with it.. lol

lostinbeta
June 2nd, 2003, 09:41 PM
Hrmmm, what about just refreshing the image source? I don't know if this will work if the image is cached, but it's worth a shot right?



<SCRIPT LANGUAGE="JavaScript">
<!--
function refreshIMG() {
document.images["myImage"].src = "imageName.jpg";
}
refreshInterval = setInterval(refreshIMG, 15000);
-->
</SCRIPT>

Put that between the &lt;HEAD&gt;&lt;/HEAD&gt; tags of your HTML document. It uses setInterval to call the function every 15000 milliseconds (15 seconds), and the function inside replaces the source of the image with the name "myImage" with the image "imageName.jpg".

Now you will have to create the image in the document so it knows what image to replace right? Well we will use a standard IMG tag that will load the original "imageName.jpg" and have the name "myImage" so the script knows to update it. Of course this tag goes in between the &lt;BODY&gt;&lt;/BODY&gt; tags.


<IMG SRC="imageName.jpg" WIDTH="xx" HEIGHT="xx" NAME="myImage">

nobody
June 2nd, 2003, 09:43 PM
I'll probably give that a shot too lost
thanks :beam:

lostinbeta
June 2nd, 2003, 09:48 PM
If it doesn't work because of cached images you can try using the pragma method to stop caching.

Between the &lt;HEAD&gt;&lt;/HEAD&gt; tags add this..

<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">


NOTE: again, not sure how well this would work, but it's worth a try.

nobody
June 3rd, 2003, 06:55 AM
lol its cool that you know all this code but dont know if it would work.
I wanna be smart

lostinbeta
June 3rd, 2003, 12:25 PM
Well I know the code yes, but I have reasons on why I don't know if will work ;)

For the image source swap, the code itself is compatible with both NS and IE, so no problem there, but if you cache the image I don't know if you refresh the source of the image with the same image if the cached image will display instead of the new version. And I don't have a webcam to test ;)

For the pragma code, I believe there are difficulties with it in IE5 (not sure about 6) so I wasn't sure how well that would work.

nobody
June 3rd, 2003, 08:41 PM
So i went ahead and tried.. but the image doesn't refresh or anything.. not really sure what to do.. well heres the source anywho..

<html>
<head>
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<SCRIPT LANGUAGE="JavaScript">
<!--
function refreshIMG() {
document.images["ccam"].src = "ccam.jpg";
}
refreshInterval = setInterval(refreshIMG, 15000);
-->
</SCRIPT>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<IMG SRC="ccam.jpg" NAME="ccam" WIDTH="320" HEIGHT="240" id="ccam">
</body>
</html>

thanks for the help so far

abzoid
June 3rd, 2003, 10:28 PM
Since your scripting is client side, it has nothing new to refresh. There is no mechanism to pull a fresh image from the server.

I know of no way to pull a fresh image from the server without reloading the entire page, which is why we used a frameset.

lostinbeta
June 3rd, 2003, 11:03 PM
Thanks for the info abzoid. I thought it was worth a try if recalling the same source image via images[].src every 15 seconds to see if that would work, I guess not :P

Iframse work just the same as framesets, so it should work perfectly fine in one if it works in a frameset.

nobody
June 4th, 2003, 03:27 PM
28 needs help:/

lostinbeta
June 4th, 2003, 03:38 PM
Well I found this... but it sounds like what we already mentioned...

http://developers.webcamworld.com/howto.html

nobody
June 4th, 2003, 03:56 PM
bwahaha... it works now.. the stupid table and iFrame are kinda pissin me off.. but hey, what can ya do?

http://xxviii.net/cam/webcam.htm

thanks a lot guy