...

View Full Version : revised image script



bst82551
01-11-2005, 01:27 AM
i have decided to change the script up a little because the last one seemed to be a little buggy, but now i seem to be having some problems with this one. Like- I'll click the one to make the pic refresh every 30 seconds. It will refresh after 30 seconds, but then it just seems to stop working and will not refresh again.



<script language="JavaScript"><!--
function pause(time) {
setTimeout('refresh()',time);
}

function pause3() {
document.images['cam'].onload = 'pause(3000)';
setTimeout('refresh()',3000);
}

function pause10() {
document.images['cam'].onload = 'pause(10000)';
setTimeout('refresh()',10000);
}

function pause30() {
document.images['cam'].onload = 'pause(30000)';
setTimeout('refresh()',30000);
}

function refresh() {
document.images['cam'].src = 'http://bst82551.ath.cx:8080/cam_1.jpg?' + Math.random();
}

function stop() {
document.images['cam'].src = 'http://bst82551.ath.cx:8181/status/images/camoff.jpg';
document.images['cam'].onload = '';
}
//--></script>


here are the links i've created for this... and the image itself.



<font size=2>
<a href="#" onclick="pause3()" title="3 seconds">3</a> -
<a href="#" onclick="pause10()" title="10 seconds">10</a> -
<a href="#" onclick="pause30()" title="30 seconds">30</a>
</font>
<br>
<img src="http://bst82551.ath.cx:8080/cam_1.jpg" name="cam" onLoad="pause(3000)" onError="stop()">


Brian

Brandoe85
01-11-2005, 01:31 AM
Maybe you need to cancel your timer with the clearTimeout() method...:rolleyes:

bst82551
01-11-2005, 01:41 AM
nothing happened when i did that. I inserted it into all logical places and tested it multiple times. Nothing changed.

Brian

glenngv
01-11-2005, 06:32 AM
The correct way to set the onload handler is:

document.images['cam'].onload = function(){pause(3000);}

If there is no parameter on the onload function, it would have been like this:

document.images['cam'].onload = pause;

bst82551
01-11-2005, 01:19 PM
whoa, it worked!!!!

Thank you so much, glenngv! I would definitely pay you for this if i had any money, haha.

Brian

bst82551
01-11-2005, 01:21 PM
by the way... brandoe85, you helped too. I had to use the clearTimeout() method to make what glenngv said in order to make the script function correctly. Thanks to you both.

Brian

bst82551
01-11-2005, 01:28 PM
the finished product can be found here:

http://bst82551.ath.cx:8181/cam/index.html

If you'd like to see it. I probably won't have the cam on, but you can still look at the source, :-).

Brian



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum