Forum Moderators: open
i have some ads codes
4 example adbrite YPN adsense clicksor
and this is a js file:
document.write('adbrite');
document.write('YPN');
document.write('ADSENSE');
document.write('clicksor');
but how i can show them randomly?(i want show a ad in my site randomly - for example for first visit my blog show adbrite ads and for second visitor show clicksor ad...)
how i can do it?
Note: Arrays are ZERO based
The more you have, the more 'random' it will appear
<form name="myFormName" method="get" action=" ">
<noscript>
<div>
If you can see this then SCRIPTS are turned OFF
</div>
</noscript>
<script type="text/javascript">
function displayRandomAd()
{
//store the adverts in arrays
heading = new Array();
theAdText = new Array();heading[0] = "heading ZERO";
theAdText[0] = "body ZERO Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec in purus a ,"
+ " dui venenatis laoreet. Integer faucibus convallis";heading[1] = "heading ONE";
theAdText[1] = "The most overlooked advantage to owning a computer is that if they foul up there\'s no law"
+ " against whacking them around a little";heading[2] = "John C. Dvorak";
theAdText[2] = "In all large corporation, there is a pervasive fear that someone, somewhere is having fun"
+ " with a computer on company time"
+ "<br\/>Networks help alleviate that fear";heading[3] = "Douglas Adams (1952 ~ 2001) Mostly Harmless";
theAdText[3] = "A common mistake that people make when trying to design something competely foolproof "
+ " is to underestimate the ingenuity of compete fools";heading[4] = "Rick Cook";
theAdText[4] = "Programming today is a race between software engineers striving to"
+ " build bigger and better idiot-proof programs, and the Universe trying to produce"
+ " bigger and better idiots"
+ "<br\/><br\/>So far, the Universe is winning";heading[5] = "George W. Bush";
theAdText[5] = "Our enemies are innovative and resourceful, and so are we. "
+ "<br\/>They never stop thinking about new ways to harm our country and our people, and neither do we";//calculate a random index
// NB the more ads you have, the less likely it is to see the same one twice in a row
index = Math.floor(Math.random() * theAdText.length);//display the ad
document.write( ' <h2>Random Ad (refresh the page to see another ad)<\/h2>'
+ '<h4> ' + heading[index] + '<\/h4>'
+ '<p>' + theAdText[index] + '\n' + '<\/p>'
);
//done
}
</script>
<script type="text/javascript">
displayRandomAd();
</script>
</form>