[GET] Simple Banner rotator script

fbrcold

Junior Member
Joined
Jul 13, 2008
Messages
179
Reaction score
314
I looked forever to find a rotator script for my banners that i could use on my php sites, facebook apps, and wordpress. I had someone develop this for me and it works perfect so I am sharing it with the community. I think it is self explanatory.

To change the size of the ads just change the size of width and height.

I hope this helps some of you.
Code:
<script type="text/javascript">
<!-- Begin
rnd.today=new Date();
rnd.seed=rnd.today.getTime();

function rnd() {
        rnd.seed = (rnd.seed*9301+49297) % 233280;
        return rnd.seed/(233280.0);
};

function rand(number) {
	var result = Math.ceil(rnd()*number);
	if (!result)result++;
        return result
};
var ad_cnt2 = 10;
var ad2 = rand(ad_cnt2);
var link2;
var adBanner2;
var width2
var height2
if (ad2==1) {
link2="http://youraffiliatelink.com";
adBanner2="http://yoursite.com/image.jpg";
width2="728";
height2="90";
alt2="Your Alt text";
}
if (ad2==2) {
link2="http://youraffiliatelink.com";
adBanner2="http://yoursite.com/image.jpg";
width2="728";
height2="90";
alt2="Your Alt text";
}
if (ad2==3) {
link2="http://youraffiliatelink.com";
adBanner2="http://yoursite.com/image.jpg";
width2="728";
height2="90";
alt2="Your Alt text";
}
if (ad2==4) {
link2="http://youraffiliatelink.com";
adBanner2="http://yoursite.com/image.jpg";
width2="728";
height2="90";
alt2="Your Alt text";
}
if (ad2==5) {
link2="http://youraffiliatelink.com";
adBanner2="http://yoursite.com/image.jpg";
width2="728";
height2="90";
alt2="Your Alt text";
}
if (ad2==6) {
link2="http://youraffiliatelink.com";
adBanner2="http://yoursite.com/image.jpg";
width2="728";
height2="90";
alt2="Your Alt text";
}
if (ad2==7) {
link2="http://youraffiliatelink.com";
adBanner2="http://yoursite.com/image.jpg";
width2="728";
height2="90";
alt2="Your Alt text";
}
if (ad2==8) {
link2="http://youraffiliatelink.com";
adBanner2="http://yoursite.com/image.jpg";
width2="728";
height2="90";
alt2="Your Alt text";
}
if (ad2==9) {
link2="http://youraffiliatelink.com";
adBanner2="http://yoursite.com/image.jpg";
width2="728";
height2="90";
alt2="Your Alt text";
}
if (ad2==10) {
link2="http://youraffiliatelink.com";
adBanner2="http://yoursite.com/image.jpg";
width2="728";
height2="90";
alt2="Your Alt text";
}
document.write('<center><a href="' + link2 + '" target="_blank">');
document.write('<img src="' + adBanner2 + '" width=' + width2 + ' height=' + height2 + ' border=0 

alt="' + alt2 + '"></a>');
document.write('</center>');
// End -->
</SCRIPT>
 
The script is good, but I don't understand why would this script generate a random number in such a complicated way..
I mean all the crap at the top of the script where it gets Date, time, then multiplies it, randomizes, etc. - all this just to get a random number between 1 and 10.

So I guess the simpler version of a script should be:

Code:
var ad2 = Math.floor((Math.random() * 10) + 1);
var link2;
var adBanner2;
var width2
var height2
if (ad2==1) {
link2="http://youraffiliatelink.com";
adBanner2="image.jpg";
width2="728";
height2="90";
alt2="Your Alt text";
}
if (ad2==2) {
link2="http://youraffiliatelink.com";
adBanner2="image.jpg";
width2="728";
height2="90";
alt2="Your Alt text";
}
if (ad2==3) {
link2="http://youraffiliatelink.com";
adBanner2="image.jpg";
width2="728";
height2="90";
alt2="Your Alt text";
}
if (ad2==4) {
link2="http://youraffiliatelink.com";
adBanner2="image.jpg";
width2="728";
height2="90";
alt2="Your Alt text";
}
if (ad2==5) {
link2="http://youraffiliatelink.com";
adBanner2="image.jpg";
width2="728";
height2="90";
alt2="Your Alt text";
}
if (ad2==6) {
link2="http://youraffiliatelink.com";
adBanner2="image.jpg";
width2="728";
height2="90";
alt2="Your Alt text";
}
if (ad2==7) {
link2="http://youraffiliatelink.com";
adBanner2="image.jpg";
width2="728";
height2="90";
alt2="Your Alt text";
}
if (ad2==8) {
link2="http://youraffiliatelink.com";
adBanner2="image.jpg";
width2="728";
height2="90";
alt2="Your Alt text";
}
if (ad2==9) {
link2="http://youraffiliatelink.com";
adBanner2="image.jpg";
width2="728";
height2="90";
alt2="Your Alt text";
}
if (ad2==10) {
link2="http://youraffiliatelink.com";
adBanner2="image.jpg";
width2="728";
height2="90";
alt2="Your Alt text";
}
document.write('<center><a href="' + link2 + '" target="_blank">');
document.write('<img src="' + adBanner2 + '" width=' + width2 + ' height=' + height2 + ' border=0 alt="' + alt2 + '"></a>');
document.write('</center>');

where in the first line you change 10 to any number of banners that you want to rotate.

Sure enough I am not an expert javascript programmer so maybe someone who is more experienced in javascript could explain to me why the complicated stuff at the top of the original script
thanks!
 
Last edited:
That's certainly a great addition and observation Harvest Golem. I tend to just use openx to or even simpler PHP rotators, but this one works for those with limited ad inventory or placements and rotates quite linearly so can be good for split-testing banners.
 
The script is good, but I don't understand why would this script generate a random number in such a complicated way..
I mean all the crap at the top of the script where it gets Date, time, then multiplies it, randomizes, etc. - all this just to get a random number between 1 and 10.

So I guess the simpler version of a script should be:

Code:
var ad2 = Math.floor((Math.random() * 10) + 1);
var link2;
var adBanner2;
var width2
var height2
if (ad2==1) {
link2="http://youraffiliatelink.com";
adBanner2="image.jpg";
width2="728";
height2="90";
alt2="Your Alt text";
}
if (ad2==2) {
link2="http://youraffiliatelink.com";
adBanner2="image.jpg";
width2="728";
height2="90";
alt2="Your Alt text";
}
if (ad2==3) {
link2="http://youraffiliatelink.com";
adBanner2="image.jpg";
width2="728";
height2="90";
alt2="Your Alt text";
}
if (ad2==4) {
link2="http://youraffiliatelink.com";
adBanner2="image.jpg";
width2="728";
height2="90";
alt2="Your Alt text";
}
if (ad2==5) {
link2="http://youraffiliatelink.com";
adBanner2="image.jpg";
width2="728";
height2="90";
alt2="Your Alt text";
}
if (ad2==6) {
link2="http://youraffiliatelink.com";
adBanner2="image.jpg";
width2="728";
height2="90";
alt2="Your Alt text";
}
if (ad2==7) {
link2="http://youraffiliatelink.com";
adBanner2="image.jpg";
width2="728";
height2="90";
alt2="Your Alt text";
}
if (ad2==8) {
link2="http://youraffiliatelink.com";
adBanner2="image.jpg";
width2="728";
height2="90";
alt2="Your Alt text";
}
if (ad2==9) {
link2="http://youraffiliatelink.com";
adBanner2="image.jpg";
width2="728";
height2="90";
alt2="Your Alt text";
}
if (ad2==10) {
link2="http://youraffiliatelink.com";
adBanner2="image.jpg";
width2="728";
height2="90";
alt2="Your Alt text";
}
document.write('<center><a href="' + link2 + '" target="_blank">');
document.write('<img src="' + adBanner2 + '" width=' + width2 + ' height=' + height2 + ' border=0 alt="' + alt2 + '"></a>');
document.write('</center>');

where in the first line you change 10 to any number of banners that you want to rotate.

Sure enough I am not an expert javascript programmer so maybe someone who is more experienced in javascript could explain to me why the complicated stuff at the top of the original script
thanks!

Where do i need to put this script? </head> or </body>

I'm not an expert you in these kinda things you know
 
Back
Top