Show Banner Ad Calculated paramter

[Total: 0    Average: 0/5]

This shows a different ad based on the parameter passed to this page.

Head Code:

 <script> 
/// Begin the construct for the Ads 
function Ad(_txt,_url,_alt,_banner,_width,_height,_parm) { 
  if (_txt)    this.txt    = _txt; 
  if (_url)    this.url    = _url; 
  if (_alt)    this.alt    = _alt; 
  if (_banner) this.banner = _banner; 
  if (_width)  this.width  = _width; 
  if (_height) this.height = _height; 
  if (_parm)   this.parm   = _parm; 
} 
Ad.prototype.URL    = function() { return this.url;    } 
Ad.prototype.TXT    = function() { return this.txt;    } 
Ad.prototype.ALT    = function() { return this.alt;    } 
Ad.prototype.BANNER = function() { return this.banner; } 
Ad.prototype.WIDTH  = function() { return this.width;  } 
Ad.prototype.HEIGHT = function() { return this.height; } 
Ad.prototype.PARM   = function() { return this.parm;   } 
//// End the construct for the Ads 

/// Begin defining the Ads. 
var myAds = new Array(); 
    myAds[0] = new Ad("Javascript Examples", 
                      "http://www.js-examples.com/", 
  "Banner Exchange", 
  "/images/green_ball1.gif", 
  "468", 
  "60", 
  "Label1"); 
    myAds[1] = new Ad("Some Javascript Examples", 
                  "http://www.js-examples.com/", 
  "Banner Exchange", 
  "/images/blue_ball1.gif", 
  "468", 
  "60", 
  "Label2"); 
    myAds[2] = new Ad("Javascript Home", 
                      "http://www.js-examples.com/", 
  "Banner Exchange", 
  "/images/red_ball1.gif", 
  "468", 
  "60", 
  "Label3"); 

/// Determine which Ad To show 
var _whichAd = 0; 
var _l = document.location.toString(); 
var _lookfor="?banner"; 
var _i = _l.indexOf(_lookfor); 
if (_i != -1) { 
  var _y = _l.substr(_i+_lookfor.length+1,_l.length); 
  for (var _a=0; _a < myAds.length; _a++) { 
    if (myAds[_a].PARM() == _y) { 
  _whichAd = _a; 
} 
  } 
} 

function goToNum(_v) {
  var _a = document.location.toString().indexOf("?");
  if (_a == -1) _a=document.location.toString().length;
  var _b = document.location.toString().substr(0,_a);
  document.location=_b+"?banner="+myAds[_v].PARM();
}
</script>

Body Code:

<script>
/// Build the string to output - and then output it. 
var _s  = ''; 
    _s += '<center>';  
    _s += '<a target="banner" '; 
_s += 'class=orange '; 
_s += 'href="' + myAds[_whichAd].URL() + '" '; 
_s += 'target="_top" '; 
_s += 'target="banner">';  
    _s += '<img src="' + myAds[_whichAd].BANNER() + '" width='; 
    _s += myAds[_whichAd].WIDTH() + ' height=' + myAds[_whichAd].HEIGHT() + ' ';  
    _s += 'alt="' + myAds[_whichAd].ALT() + '" border=1 /><br /></a>';  
    _s += ' ' + myAds[_whichAd].TXT() + ' ';  
    _s += '</center>'; 
document.write(_s);  
</script> 
<BR /><BR /><BR />
<script>
for (var i=0; i<myAds.length; i++)
  document.write("<a href=javascript:goToNum("+i+")>goto banner #"+i+": "+myAds[i].TXT()+"</a><BR>");
</script>

Times Viewed: 7

Leave a Reply

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