Javascript Banner Rotator Problem

gavin681's picture

They have: 184 posts

Joined: May 2001

Hello everyone,

I am using this simple Javascript on my site at: http://www.fast-sites.net/about.htm to rotate 2 banners. They change when page is refreshed.

I have only 2 problems:

1. How do I get rid of that border around the banners?

2. Is there anyway to have the banner ad links open up in a new window?

This is the code I'm using:

<script LANGUAGE="JavaScript">

');
document.write('');
document.write('');
// End -->
</script>

Any help would be much appreciated,

Thanks,
Gavin

openmind's picture

He has: 945 posts

Joined: Aug 2001

My God! A JavaScript question I can answer!

To solve both your problems in one fell swoop chnge the line for your url to include target="_blank" to open the ad in a new window and to get rid of the border just add border="0" to the lines where you call the banner gif.

Hope that helps though I'm probably wrong! I doubt my abilities at times!! Smiling

gavin681's picture

They have: 184 posts

Joined: May 2001

I tried both but didn't work.

I change the code to below but the banners disapeared.

<script LANGUAGE="JavaScript">

');
document.write('');
document.write('');
// End -->
</script>

openmind's picture

He has: 945 posts

Joined: Aug 2001

See, I told you it might not work! Smiling Can't help then mate. I though it would but obviously not. Sorry! Sad

dk01's picture

He has: 516 posts

Joined: Mar 2002

ok... you could have the image be placed by your script but then have the link activate a js function and you could pass the url and have it open a new window. this could be one workaround you could explore. not sure about the border thing. use css maybe?
-dk

Abhishek Reddy's picture

He has: 3,348 posts

Joined: Jul 2001

I don't get it. The code doesn't have an output for or ending the tag with a >. Also you've used target="_top" rather than target="[var target]". The target value is even declared on the same line as the url var is declared. Sad

There are a few bugs all over. I'll review the code again and see if I can provide with a fixed up version. Smiling

Abhishek Reddy's picture

He has: 3,348 posts

Joined: Jul 2001

Ok, here's a version that I worked on. I haven't tested it. I've only gone through it correcting whatever I came across that seemed wrong. Sticking out tongue

&lt;script LANGUAGE="JavaScript"&gt;

<!-- Begin
var how_many_ads = 2;
var now = new Date()
var sec = now.getSeconds();
var ad = sec % how_many_ads;
ad +=1;
if (ad==1) {
url="http://hop.clickbank.net/?dollartemp/dollart";
target="_blank";
banner="http://www.fast-sites.net/images/banner_ad.gif";
width="468";
height="60";
border="0";
}
if (ad==2) {
url="http://www.bahamasb2b.com";
target="_blank";
banner="http://www.fast-sites.net/images/banner_ad2.gif";
width="468";
height="60";
border="0";
}
document.write('<center>');
document.write('<a href=\"' + url + '\"');
document.write(' target=\"' + target + '\">');
document.write('<img src=\"' + banner + '\"');
document.write(' border=\"' + border + '\"');
document.write(' width=\"' + width + '\"');
document.write(' height=\"' + height + '\">');
document.write('</a>');
document.write('</center>');
// End -->
&lt;/script&gt;
'

gavin681's picture

They have: 184 posts

Joined: May 2001

Many thanks Abhishek Reddy.

That code worked! Excellent!

Thanks again.
Gavin

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.