Rotate Ad Banner II

[Total: 0    Average: 0/5]

This shows a method to have an image change every 5 seconds. Each image must be the same size.

Body Code:

<script type=text/javascript>
var adImg = 0; // used to index the array
var adURL = 1; // used to index the array
var ad = new Array();
var adOn = 0; // which ad is displayed currently
function addImage(_i,_u) {
  ad[ad.length?ad.length:0] = new Array();
  ad[ad.length-1][adImg] = _i;
  ad[ad.length-1][adURL] = _u;
}
if (document.images) {
addImage("http://www.js-examples.com/js/pic1.gif",
         "http://www.js-examples.com/");
addImage("http://www.js-examples.com/js/pic2.gif",
         "http://www.js-examples.com/js/");
} 

function cycleAds() { 
  if (document.images && document.adBanner.complete) { 
    adOn = ++adOn % ad.length;
    document.images.adBanner.src = ad[adOn][adImg]; 
  } 
}
var delay = 5; // time in seconds to delay between ads.
var adTimer = null;
adTimer = setInterval("cycleAds()",delay*1000);
function gotoAd() { 
document.location.href = ad[adOn][adURL];
}
function showStatus() {
  status = "GoTo: "+ad[adOn][adURL];
}
</script>
<BR><a href='javascript:gotoAd()' onmouseout='status=""' onmouseover='showStatus();return true;'><img border=0 alt='' name=adBanner src='http://www.js-examples.com/js/pic1.gif'></a>

Times Viewed: 9

Leave a Reply

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