JavaScript-switching?

They have: 4 posts

Joined: Jan 2006

Okay, on my site, I have a webcam, using JavaScript.

They have: 11 posts

Joined: Jan 2006

Can't see any reason why not.

Try this - you'll need the code on both pages, with each one pointing to the other. You'll note that the setting is currently 5 seconds - you'll need to change this in the META tag and the setTimeout line. Also don't forget to change the URL in the line var sTargetURL = "redirectiontarget.htm"; . On page 1 point to page 2 and vice versa. Crude but effective

Code from:

http://grizzlyweb.com/webmaster/javascripts/redirection.asp#Timed-Redirect

Timed Redirection Example

<script language="JavaScript">

</script>

<script language="JavaScript1.1">

</script>

Loading redirection target
In approx. 5 seconds the redirection target page should load.
If it doesn't please select the link above.

They have: 4 posts

Joined: Jan 2006

Actually, I think I explained that a little vaguely... I'm not looking for a re-direct script. Here, let me go into detail.

What I am trying to do is take the following two scripts, and make them switch every ten seconds, but still stay on the main page... (Here is the page I am trying to put it on.)

&lt;script LANGUAGE="JavaScript"&gt;
<!--
browserType = navigator.appName;
newImage = new Image();
document.onstop = document_onstop;

function startstop_onclick()
{
if (startstop.value == "Turn Me Off")
{
stopLoad();
}
else
{
startstop.value = "Turn Me Off";
newImage.onload=loadNewImage;
loadNewImage();
}
}

function document_onstop()
{
stopLoad();
}

function stopLoad()
{
newImage.onload="";
startstop.value = "Turn Me On";
window.status = "On an Easter Egg Hunt?";
}

function loadNewImage()
{
    uniq = new Date();
    uniq = uniq.getTime();
    document.images.webcam32.src=newImage.src;
    newImage.src="http://192.168.1.103:7778/video/pull?"+uniq;
    window.status = "On an Easter Egg Hunt?";   
}
function initialImage()
{
uniq = new Date();
uniq = uniq.getTime();
newImage.onload=loadNewImage;
newImage.src="http://192.168.1.103:7778/video/pull?"+uniq;
    document.images.webcam32.onload="";

}

if (browserType == "Netscape")
{
document.write('<IMG SRC="http://192.168.1.103:7778/video/push" width=155 height=116 style="width: 155px; height: 116px; background-image: URL(<a href="http://armoth.sytes.net:1984/~sonicadvdx/Layout2/Live_off_t.JPG" class="bb-url">http://armoth.sytes.net:1984/~sonicadvdx/Layout2/Live_off_t.JPG</a>);">');
}
else
{
document.write('<IMG SRC="http://192.168.1.103:7778/video/pull" name=webcam32 onload="initialImage()" width=155 height=116 style="width: 155px; height: 116px; background-image: URL(<a href="http://armoth.sytes.net:1984/~sonicadvdx/Layout2/Live_off_t.JPG" class="bb-url">http://armoth.sytes.net:1984/~sonicadvdx/Layout2/Live_off_t.JPG</a>);">');
}
//-->

if (browserType == "Netscape")
{
document.write('<style type= "text/css"> #chatbox { position: relative; top: -25px; } </style>');
}
&lt;/script&gt;
'

That is the first webcam to be cycled through.

&lt;script LANGUAGE="JavaScript"&gt;
<!--
browserType = navigator.appName;
newImage = new Image();
document.onstop = document_onstop;

function startstop_onclick()
{
if (startstop.value == "Turn Me Off")
{
stopLoad();
}
else
{
startstop.value = "Turn Me Off";
newImage.onload=loadNewImage;
loadNewImage();
}
}

function document_onstop()
{
stopLoad();
}

function stopLoad()
{
newImage.onload="";
startstop.value = "Turn Me On";
window.status = "You are watching my webcam... I am happy...";
}

function loadNewImage()
{
    uniq = new Date();
    uniq = uniq.getTime();
    document.images.webcam32.src=newImage.src;
    newImage.src="http://192.168.1.103:7777/video/pull?"+uniq;
    window.status = "You are watching my webcam... I am happy...";   
}
function initialImage()
{
uniq = new Date();
uniq = uniq.getTime();
newImage.onload=loadNewImage;
newImage.src="http://192.168.1.103:7777/video/pull?"+uniq;
    document.images.webcam32.onload="";

}

if (browserType == "Netscape")
{
document.write('<IMG SRC="http://192.168.1.103:7777/video/push" width=320 height=240 style="width: 320px; height: 240px; background-image: URL(<a href="http://armoth.sytes.net:1984/~sonicadvdx/Layout2/Live_off.JPG" class="bb-url">http://armoth.sytes.net:1984/~sonicadvdx/Layout2/Live_off.JPG</a>);">');
}
else
{
document.write('<IMG SRC="http://192.168.1.103:7777/video/pull" name=webcam32 onload="initialImage()" width=320 height=240 style="width: 320px; height: 240px; background-image: URL(<a href="http://armoth.sytes.net:1984/~sonicadvdx/Layout2/Live_off.JPG" class="bb-url">http://armoth.sytes.net:1984/~sonicadvdx/Layout2/Live_off.JPG</a>);">');
}
//-->
if (browserType == "Netscape")
{
document.write('<style type= "text/css"> #chatbox { position: relative; top: -25px; } </style>');
}
&lt;/script&gt;
'

And, this is the second one. (Yes, they are essentially the same thing, but they display two totally different things.)

If you go to the page that I want to do this on, you should see a section on the right side of the page, called 'Webcam Mini' with an image that says 'Adam Live! 2' and such. That image is the background image of where I need this script to be. There currently is a broken image display box (Unless you're using Firefox, of course.) in place of the webcam, because the webcam is not turned on yet.

But, that's beside the point. Is there anyway to take those two scripts and cycle them every ten seconds, as to show both of the webcams, using JavaScript?

Thanks again,
~Adam "SonicAdvDX"

They have: 5,633 posts

Joined: Jan 1970

LOL! I was wondering how you got a cam working with javascript...
Your just refreshing the image!

How well do you know javascript?
Can I tell you what to do or do you want me to edit your current script?
Do you know any php/asp? Does your server support eather?

They have: 4 posts

Joined: Jan 2006

Um, well, would it be too much trouble for you to do it? I mean, my friend made that script for me, so I really don't know much about JavaScript, or PHP.

~Adam "SonicAdvDX"

They have: 4 posts

Joined: Jan 2006

Um... Sorry about double posting, but can anybody help me with this?

~Adam "SonicAdvDX"

CptAwesome's picture

He has: 370 posts

Joined: Dec 2004

var showing_image = 0;
function swap_cam(){
var minutes = 5 // change this to whatever
obj = documnet.getElementById('webcam_image');
if(showing_image == 1){
new_src = 'images/cam1.jpg';
showing_image = 0;
}else{
new_src = 'images/cam2.jpg';
showing_image = 1;
}
setTimeout("swap_cam()",minutes*60*1000);
}


then in the html put
<body onload="swap_cam()">

<img src="images/cam1.jpg" id="webcam_image" />
'

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.