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;