Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-11-2005, 12:27 AM   PM User | #1
bst82551
New to the CF scene

 
Join Date: Jan 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
bst82551 is an unknown quantity at this point
revised image script

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.

Code:
<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.

Code:
<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

Last edited by bst82551; 01-11-2005 at 12:33 AM..
bst82551 is offline   Reply With Quote
Old 01-11-2005, 12:31 AM   PM User | #2
Brandoe85
teh Moderatorinator


 
Join Date: Sep 2004
Location: USA
Posts: 2,472
Thanks: 4
Thanked 40 Times in 40 Posts
Brandoe85 will become famous soon enough
Maybe you need to cancel your timer with the clearTimeout() method...
__________________
-Brando
Why using tables for eating is stupid!
Brandoe85 is offline   Reply With Quote
Old 01-11-2005, 12:41 AM   PM User | #3
bst82551
New to the CF scene

 
Join Date: Jan 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
bst82551 is an unknown quantity at this point
nothing happened when i did that. I inserted it into all logical places and tested it multiple times. Nothing changed.

Brian
bst82551 is offline   Reply With Quote
Old 01-11-2005, 05:32 AM   PM User | #4
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
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;
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Old 01-11-2005, 12:19 PM   PM User | #5
bst82551
New to the CF scene

 
Join Date: Jan 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
bst82551 is an unknown quantity at this point
whoa, it worked!!!!

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

Brian
bst82551 is offline   Reply With Quote
Old 01-11-2005, 12:21 PM   PM User | #6
bst82551
New to the CF scene

 
Join Date: Jan 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
bst82551 is an unknown quantity at this point
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 is offline   Reply With Quote
Old 01-11-2005, 12:28 PM   PM User | #7
bst82551
New to the CF scene

 
Join Date: Jan 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
bst82551 is an unknown quantity at this point
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
bst82551 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:53 AM.


Advertisement
Log in to turn off these ads.