Skip to content

Instantly share code, notes, and snippets.

@ratamacue
Last active December 25, 2015 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ratamacue/6943655 to your computer and use it in GitHub Desktop.
Save ratamacue/6943655 to your computer and use it in GitHub Desktop.
This is an example of the HTML a publisher can use to place any collection of ads on his or her site so that all will be hidden except one random ad for each page refresh. You can see an example of the output here: http://jsfiddle.net/TUats/embedded/result/
<div id="cj_rolling_container">
<!-- Put Your Ads In This Container Like So -->
<a href='http://www.kqzyfj.com/click-6743399-11396752' target='_top'>
<img src='http://www.lduhtrp.net/image-6743399-11396752' width='300' height='250' alt='' border='0' />
</a>
<a href='http://www.kqzyfj.com/click-6743399-11396757' target='_top'>
<img src='http://www.lduhtrp.net/image-6743399-11396757' width='300' height='250' alt='' border='0' />
</a>
<a href='http://www.kqzyfj.com/click-6743399-11396760' target='_top'>
<img src='http://www.lduhtrp.net/image-6743399-11396760' width='300' height='250' alt='' border='0' />
</a>
<a href='http://www.kqzyfj.com/click-6743399-11396761' target='_top'>
<img src='http://www.lduhtrp.net/image-6743399-11396761' width='300' height='250' alt='' border='0' />
</a>
</div>
<script>
var elements = document.querySelectorAll("#cj_rolling_container > *");
var choice = Math.floor(Math.random()*elements.length);
for(var i=0; i<elements.length; i++){
if (i!==choice) elements[i].style.display='none';
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment