• 0

Help with switching ads code


Question

Does anyone know how I would go around switching between different codes for ads on a website? I'm currently going between two ad companies, and those of you who don't know, usually ads tend to not only be the image+link, but also scripted to count visitors and if clicked on, will count that.

I need a code, java or whatever, to switch between two ad scripts.

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

Can you use any server side scripts? Like asp perhaps? I would recommend a server side script before going the js route but if you have to go js, try this:

<script language="javaScript">
<!--
var img_rnd = new Array ();
img_rnd[0] = 'AD CODE 1 GOES HERE';
img_rnd[1] = 'AD CODE 2 GOES HERE';

var i = Math.floor(2*Math.random());

document.write(img_rnd[i]);

//-->
</script>

Credit to the source of this code. I tweaked it a bit for your purpose.

Disclaimer: I tested this briefly and it worked for me. However, I am no expert at javascript so it would be great if someone who IS experienced with js could look it over first and say if it is an ok script.

Well it can be done with js but I don't think its possible to keep track of the ad that was served unless php is involved somewhere.

The ad company normally takes care of the tracking on their end. Like Google adsense, they just give you some js to put on your site and it reports all the necessary info back to their servers. As I understand it, he just needs a way to rotate these codes.

Link to comment
Share on other sites

  • 0

The javascript in the ad code seems to mess up the javascript there. But no worries, I'm switching to a new host that properly supports php in the near future so I'll just use the first code posted.

Thanks guys!

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.