开发者

Very simple Javascript ad placement engine

开发者 https://www.devze.com 2023-01-27 18:38 出处:网络
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 a

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

精彩评论

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