ad rotator ad nauseum

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

ad rotator ad nauseum

Post by Vegan »

After Expression Web crashed and a few excited utterances I have gone back to the JavaScript which seems to be easier to assemble a page with.

On a game review, there is a section called "AS TESTED" which provides a PHP include of a table with machine specs and a image of the crappy WEI

so looking at my PHP usage, I have attempted over and over and I have not been able to get it to work right.

Code: Select all

//Global variable that stores advertising banners.
var ads = new Array();
//Function that starts when the page finished loading.
window.onload = function(){
  //Adds information about the new banners.
  ads.push(<iframe src="http://rcm.amazon.com/e/cm?lt1=_blank&bc1=000000&IS2=1&bg1=FFFFFF&fc1=000000&lc1=0000FF&t=cpa07-20&o=1&p=8&l=as4&m=amazon&f=ifr&ref=ss_til&asins=B0062U5KG6" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>);
  ads.push(<iframe src="http://rcm.amazon.com/e/cm?lt1=_blank&bc1=000000&IS2=1&bg1=FFFFFF&fc1=000000&lc1=0000FF&t=cpa07-20&o=1&p=8&l=as4&m=amazon&f=ifr&ref=ss_til&asins=B0076DO5A0" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>);
  ads.push(<iframe src="http://rcm.amazon.com/e/cm?lt1=_blank&bc1=000000&IS2=1&bg1=FFFFFF&fc1=000000&lc1=0000FF&t=cpa07-20&o=1&p=8&l=as4&m=amazon&f=ifr&ref=ss_til&asins=B0053BSMPQ" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>
);

  //Starting rotation with the first banner.
  ad_rotate(0);
}

function ad_rotate(active){
  //Gets the div that will display banners.
  var ad_element = document.getElementById("ad");

  //Prints a new link with image in advertising box.
  //ad_element.innerHTML = "<a href=\""+ads[active][0]+"\"><img src=\""+ads[active][1]+"\" alt=\""+ads[active][2]+"\" title=\""+ads[active][2]+"\" /></a>";

  //Switches to the next banner.
  active++;

  //If the counter has reached the end, it shall start again from zero.
  if(active >= ads.length){
    active = 0;
  }
}
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: ad rotator ad nauseum

Post by Vegan »

This DOM innerHTML is a convenient way to compartmentalize the adds

All that is needed is to create a <div> with that id tad, and then the div is populated
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: ad rotator ad nauseum

Post by Vegan »

I noticed ads.push was not being liked by the facebook like button so I had to resort to ads[1] etc to stuff an array

Code: Select all

function showads(number) {
	for (i=0; i<number; i++) {
		document.write(amazonads[Math.floor(Math.random()*amazonads.length)]);
	}
}
grabs the desired number of ads from the array declared

i plan to inline test this tomorrow
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: ad rotator ad nauseum

Post by Vegan »

testing this AM has resulted in success.

<script type="text/javascript">
showads(8);
</script>

is now all I need to show a given number of ads from a pool

now the fun part, to put 200 different games to select from for the ads
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
Post Reply