Rotate Multiple Banner Ads

[Total: 0    Average: 0/5]

This shows how to have multiple banner ads rotate at an interval.

Head Code:

<script type=text/javascript src="http://www.js-examples.com/bin/div_construct2.js"></script>
<script type=text/javascript>
var _banners = new Array();
function addBanner(_bannerHTML){
  _banners[_banners.length?_banners.length:0]=_bannerHTML;
}
addBanner("<a href='http://www.js-examples.com/'><img border=0 alt='image 1' src='http://www.js-examples.com/data/pic1.gif'></a>");
addBanner("<a href='http://www.js-examples.com/'><img border=0 alt='image 2' src='http://www.js-examples.com/data/pic2.gif'></a>");
addBanner("<a href='http://www.js-examples.com/'><img border=0 alt='image 3' src='http://www.js-examples.com/data/pic3.gif'></a>");
addBanner("<a href='http://www.js-examples.com/'><img border=0 alt='image 4' src='http://www.js-examples.com/data/pic4.gif'></a>");
var div2 = new NewDiv2(window, "banner", _banners[0],0,0,50,50,500,"ABSOLUTE");
var count=0; /* which one to start with */
function doIt() {
count++;
count%=_banners.length;
div2.setBody(_banners[count]);
}
setInterval('doIt()',5000);
</script>

Body Code:

<script type=text/javascript>
div2.output();
</script>

Times Viewed: 4

Leave a Reply

Your email address will not be published. Required fields are marked *