开发者

Very simple Javascript ad placement engine

I have ten different banner ads uploaded on my site. I want to make a Javascript program that will 开发者_Go百科randomly show one each time a page is loaded. How would I do this?


you save the urls to an array and then pick an index with a random function between 0-9 and your done

function:

var rand_no = Math.ceil(10*Math.random())

array

var image=new Array(); 
image[0]="image.jpg";       
image[1]="image.jpg";
image[2]="image.jpg";

etc

alert(image[rand_no]);


Why not do it server-side? i.e. before rendering the page, you pick one banner from your server?

If you really must do it using javascript, consider using AJAX


Google is overwhelming with ad rotators. Checkout:

  • The JavaScript Source: Text Effects: Banner Ad Rotator
  • A JavaScript Banner Ad Rotator Script
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜