Multiple Webcams
June 9, 2004 12:43 PM   Subscribe

I'm trying to get a bunch of webcams running on the same page. I found a Javascript refresh script, and tried to adapt it to work for more than one cam. Of course, if I had any knowledge of Javascript, I might have succeded, but I don't, so take a look inside and lend me a hand, if you please.

Here's what I have:




var refreshrate1=5; //SECONDS BETWEEN REFRESH
var image1="http://82.35.18.32:8080/gobcam.jpg"; //IMAGE NAME
var imgheight1=240; //IMAGE HEIGHT
var imgwidth1=320; //IMAGE WIDTH

function refresh(){
document.images["pic1"].src=image1+"?"+new Date();
setTimeout('refresh()', refreshrate1*1000);
}

document.write('');

if(document.images.pic1)window.onload=refresh;


var refreshrate2=5; //SECONDS BETWEEN REFRESH
var image2="http://82.35.21.220:8080/smurgcurmpurp.jpg"; //IMAGE NAME
var imgheight2=240; //IMAGE HEIGHT
var imgwidth2=320; //IMAGE WIDTH

function refresh(){
document.images["pic2"].src=image2+"?"+new Date();
setTimeout('refresh()', refreshrate2*1000);
}

document.write('');

if(document.images.pic2)window.onload=refresh;




The second cam works fine, but the first cam doesn't work at all. Any suggestions?
posted by Orange Goblin to Computers & Internet (2 answers total)
 
You have two functions named refresh(), which are interfering with each other. Try controlling both images from within the same function:

function refresh(){
document.images["pic1"].src=image1+"?"+new Date();
document.images["pic2"].src=image2+"?"+new Date();
setTimeout('refresh()', refreshrate1*1000);
}
posted by ook at 1:05 PM on June 9, 2004


Response by poster: Aaah, I see. I thought refresh was a non-user defined command. I'll give your suggestion a go.
posted by Orange Goblin at 1:20 PM on June 9, 2004


« Older Home remedies for coughs   |   Mac OS 10.2.8. Pressing shift a couple of times... Newer »
This thread is closed to new comments.