Just to be clearer about the code in my previous post - The image[0] one will display 50% of the time in random fashion. Of the 4 others, they will as a group display 50% of the time in random fashion. 50/4 is 12.5, so each will display 12.5% of the time. It's possible to break it down further, but the code gets more complex. A different approach might be in order:
Code:
<script type="text/javascript">
//store the images' html and percent in the images array as objects
var images = [], limit = 0, imagepointer = -1,
index = Math.floor(Math.random() * 100);
images[0] = {html: "<a href='URL1'><img style='border:none;' src='IMAGE1'/></a>", percent: 50};
images[1] = {html: "<a href='URL2'><img style='border:none;' src='IMAGE2'/></a>", percent: 30};
images[2] = {html: "<a href='URL3'><img style='border:none;' src='IMAGE3'/></a>", percent: 10};
images[3] = {html: "<a href='URL4'><img style='border:none;' src='IMAGE4'/></a>", percent: 5};
images[4] = {html: "<a href='URL5'><img style='border:none;' src='IMAGE5'/></a>", percent: 5};
while (++imagepointer < images.length){
limit += images[imagepointer].percent;
if(index < limit){
document.write(images[imagepointer].html);
break;
}
}
//done
</script>
Bookmarks