Slide Show Redirection

W

Wazz Up

Hi,

I'm trying run an image slide show where the images rotate once each,
then after the last image in the array has been displayed for the
specified amount of time, a redirection to another page occurs. The
problem I'm having is that the redirection happens as soon as the last
image is displayed.

Here's an example of a normal version where the images rotate
continuously and the redirect version that isn't working properly:

http://www.xlectric.com/ftb/images/stest.html

Is there something I'm doing wrong with the counter or the if statement
that causes the redirect ?

Any help/suggestions will be appreciated.

Later, Art.
 
L

Lee

Wazz Up said:
Hi,

I'm trying run an image slide show where the images rotate once each,
then after the last image in the array has been displayed for the
specified amount of time, a redirection to another page occurs. The
problem I'm having is that the redirection happens as soon as the last
image is displayed.

Here's an example of a normal version where the images rotate
continuously and the redirect version that isn't working properly:

http://www.xlectric.com/ftb/images/stest.html

Is there something I'm doing wrong with the counter or the if statement
that causes the redirect ?

document.sbase.src = s_imgs[s_count].src;
s_count++;

if (s_count >= s_imgs.length)
{
window.location.replace('sdest.html');
}

When you execute that first line with s_count indexing your last
image, that image is displayed, and then s_count is incremented
and then you test to see if it is >= s_imgs.length (it will be)
and so you redirect.

Re-arrange those lines like this:

if (s_count >= s_imgs.length)
{
window.location.replace('sdest.html');
}
else
{
document.sbase.src = s_imgs[s_count].src;
s_count++;
}
 
M

McKirahan

Wazz Up said:
Hi,

I'm trying run an image slide show where the images rotate once each,
then after the last image in the array has been displayed for the
specified amount of time, a redirection to another page occurs. The
problem I'm having is that the redirection happens as soon as the last
image is displayed.

Here's an example of a normal version where the images rotate
continuously and the redirect version that isn't working properly:

http://www.xlectric.com/ftb/images/stest.html

Is there something I'm doing wrong with the counter or the if statement
that causes the redirect ?

Any help/suggestions will be appreciated.

Later, Art.

On the Redirect page I get an error at:
pre_img.src = s_imgs[s_pre].src;
because "s_pre" is 5.

I took the liberty of modifying your code and it now works for me.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Slide Redirect</title>
<meta name="title" content="Slide Redirect" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<base href="http://www.xlectric.com/ftb/images/sredirect.html" />
<script type="text/javascript">
// Xlectric Script
var s_count = 0;
var s_imgs = new Array();
s_imgs[0] = new Image();
s_imgs[0].src = "ftb01look1.jpg";
s_imgs[1] = new Image();
s_imgs[1].src = "ftb02look2.jpg";
s_imgs[2] = new Image();
s_imgs[2].src = "ftb03yawn1.jpg";
s_imgs[3] = new Image();
s_imgs[3].src = "ftb04look3.jpg";
s_imgs[4] = new Image();
s_imgs[4].src = "ftb05argue1.jpg";
var pre_img = new Image();
function slideShow() {
if (s_count >= s_imgs.length) {
window.location.href = 'sdest.html';
return;
}
document.sbase.src = s_imgs[s_count].src;
s_count++;
setTimeout("slideShow();",2000);
}
</script>
<link rel="stylesheet" href="stest.css" type="text/css" />
</head>
<body onload="slideShow();">
<div class="ctr">
<p>Rotation With Redirect</p>
<img src="ftb01look1.jpg" name="sbase" width="400" height="220" border="0"
alt="From The Birds" />
</div>
</body>
</html>



1) "s_imgs" can be declared outside of the function.

2) I didn't understand what the following was for so I removed it:

var s_pre = 1;

pre_img.src = s_imgs[s_pre].src;
s_pre++;

if (s_pre >= s_imgs.length - 1)
{
pre_img.src = "../thebirds400x218.jpg";
}

3) I changed 'window.location.replace('sdest.html');' to:

window.location.href = 'sdest.html';
return;
 
W

Wazz Up

Thanks very much to both of you for your help and explanations. They
work like a charm ! Looks like part of the problem is that I put the
cart in front of the horse. Never really knew what that meant until just
now. lol

Outside of return true and return false for rollovers and onclicks, I'm
not to clear on using return in a function. All I know is if a condition
is met, I can use return to exit the function.

I put s_imgs inside the function to prevent them from preloading all at
once. I'm trying to preload them one at a time, in a sequence that's one
ahead of the image that is currently being displayed. My attempt to
accomplish that is to create a new Image() constructor (var pre_img =
new Image();) and assign an increment value to it that is one greater
than the image that is being displayed in the sbase image tag (using var
s_pre = 1;). That is a complete shot in the dark on my part. It does
work with WebTV and a PC with dial-up and a slow processor though. But
then again, that might be considered improper and/or a hack, so I'm open
to any suggestions you may have.

I shouldn't have used location.replace() for these examples, sorry about
that. I grabbed it in a hurry from an iframe slide show that I have.
Using it in that (iframe) context is good though, as it eliminates
excessive use of the back button by replacing the current page in the
history with the next one.

Once again, thanks much for the help. Means everything to me.

Later, Art.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Slide Show 1
Number list to display in the slide show 3
Slide show question 4
Help with a slide show 3
slide show in vb 11
Flip-Cards with Local Images 1
<div> help 1
Slide show and Sql 1

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
KetoBurn
Top