Ad Rotator

in Tutorials on 27 Feb 2010

Make an HTML or script block.   

The script already has 3 banners in it so you get an idea where the URL's, ALT's and image location suppose to be.

Make sure you make your banners all the same size.  Currently they're 120x600.  There are 2 instances.  Change them both if using a different size. ie. 468x60

The images will rotate when the page refreshes.

<SCRIPT LANGUAGE="javascript">
<!-- Copyright 2000 - Galichon Enterprises, Inc. rich@galichon.net http://www.galichon.net
// Permission granted to SimplytheBest.net to list the script in the DHTML scripts library
// Courtesy of SimplytheBest.net - http://simplythebest.net/scripts/
function banner(img_source,url,alt,chance){
this.img_source = img_source;
this.url = url;
this.alt = alt;
this.chance = chance;
}
function display() {
with (this) document.write("<A HREF=" + url + "><IMG SRC='" + img_source + "' WIDTH=120 HEIGHT=600 BORDER=0 ALT='" + alt + "'></A>");
}
banner.prototype.display = display;
banners = new Array();

banners[0] = new banner("http://www.chevyavalancheclub.com/gtgs/2010%20chevy%20avalanche%20meet%20120x600%201.png",
"http://www.chevyavalancheclub.com/index.php/board,281.0.html",
"2010 Chevy Avalanche National Meet",
10);
banners[1] = new banner("http://www.chevyavalancheclub.com/gtgs/2010%20chevy%20avalanche%20meet%20120x600%202.png",
"http://www.chevyavalancheclub.com/index.php/board,281.0.html",
"2010 Chevy Avalanche National Meet",
10);
banners[2] = new banner("http://www.chevyavalancheclub.com/Vendors/TPC-600-animation.gif",
"http://www.gatorbackcoatings.com/",
"Gatorback Coatings",
10);


sum_of_all_chances = 0;
for (i = 0; i < banners.length; i++) {
sum_of_all_chances += banners[i].chance;
}
function display_banner() {
chance_limit = 0;
randomly_selected_chance = Math.round((sum_of_all_chances - 1) * Math.random()) + 1;
for (i = 0; i < banners.length; i++) {
chance_limit += banners[i].chance;
if (randomly_selected_chance <= chance_limit) {
document.write("<A HREF=" + banners[i].url + "><IMG SRC='" + banners[i].img_source + "' WIDTH=120 HEIGHT=600 BORDER=0 ALT='" + banners[i].alt + "'></A>");
return banners[i];
break;
}
}
}
//-->
</SCRIPT><SCRIPT LANGUAGE="javascript">
<!--
top_banner = display_banner();
//-->
</SCRIPT>


Demo



idesignSMF Team
Mick is an American theme designer for Simple Machines Forum software currently living in South Florida, USA. He runs idesignSMF.com and started tinkering with SMF in 2006 where he created several SMF forums of his own before he founded idesignSMF in 2009 to which he is dedicated full time.

idesignSMF.com | SimpleMachines.org



0 Comments

rocket_launch

Professional & Impressive. We provide top quality free SMF themes with awesome support.