Rotating Banner Question

I

Ian Hubling

I'm trying to complete a rotating banner ad within a page I have. The
rotating add has four images that rotate in three-second increments.
I've got the images to rotate ok - but now I want to go one step
further and can't figure out how to do it...

I want to have it so that when the person clicks on the specific ad,
they are taken to a URL that is unique to each ad.

I presume I would have to surround the img tag with an href tag, but
how would I reference the array to get the correct URL?? HELP.

Here is the code I'm using. Any help would be appreciated.

I've omitted unnecessary parts of the page.

-----------------------------------------------
<head>
<script>
var myPix, imCt, thisAd;
myPix=new Array("images/banner01.jpg", "images/banner02.jpg",
"images/banner03.jpg", "images/banner04.jpg");
imgCt=myPix.length;
var thisAd=0;
function rotate()
{
thisAd++
if(thisAd==imgCt)
{
thisAd=0;
}
document.adBanner.src=myPix[thisAd];
setTimeout("rotate()",3*1000);
}
</script>
</head>


<body onLoad="rotate();">
<div align="center">
<img src="images/banner01.jpg" name="adBanner"/></div>
</body>
 
I

Ian Hubling

Ian Hubling said:
I'm trying to complete a rotating banner ad within a page I have. The
rotating add has four images that rotate in three-second increments.
I've got the images to rotate ok - but now I want to go one step
further and can't figure out how to do it...

I want to have it so that when the person clicks on the specific ad,
they are taken to a URL that is unique to each ad.

I presume I would have to surround the img tag with an href tag, but
how would I reference the array to get the correct URL?? HELP.

Here is the code I'm using. Any help would be appreciated.

I've omitted unnecessary parts of the page.

-----------------------------------------------
<head>
<script>
var myPix, imCt, thisAd;
myPix=new Array("images/banner01.jpg", "images/banner02.jpg",
"images/banner03.jpg", "images/banner04.jpg");
imgCt=myPix.length;
var thisAd=0;
function rotate()
{
thisAd++
if(thisAd==imgCt)
{
thisAd=0;
}
document.adBanner.src=myPix[thisAd];
setTimeout("rotate()",3*1000);
}
</script>
</head>


<body onLoad="rotate();">
<div align="center">
<img src="images/banner01.jpg" name="adBanner"/></div>
</body>

Hi,
one suggestion would be to create a URL array of corresponding destinations
and
add an onclick handler to the image which uses the array and thisAd to open
the
appropriate destination.

myURL=new Array( "url1", url2", url3", url4");

function newWindow()
{
// alert( "you clicked " + thisAd);
window.open( myURL[thisAd]); // or a redirect
}

and

<img src="hook1.jpg" name="adBanner"/ onclick="newWindow();"></div>
Thank you very much! I modified it slightly from your response - but
you gave me exactly what I was looking for. Here's the script I ended
up with. Works like a charm!

//-------------------------------------------------------

<head>
<script>
var myPix, imCt, thisAd;
myPix=new Array("images/banner02.jpg", "images/banner03.jpg",
"images/banner04.jpg");
imgCt=myPix.length;
var thisAd=0;
function rotate()
{
thisAd++
if(thisAd==imgCt)
{
thisAd=0;
}
document.adBanner.src=myPix[thisAd];
setTimeout("rotate()",3*1000);
}

myURL=new Array("url1.htm", "url2.htm","url3.htm");
function vgotoad()
{
window.location.href(myURL[thisAd]);
}
</script>
</head>

<body onLoad="rotate();">

<div align="center"><img src="images/banner01.jpg" name="adBanner"
onClick="vgotoad();"></div>
</body>
 

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

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top