一天弹出一次的广告JS代码

有一个页面有两条图片广告,当用户访问这个页面时按十分之一的概率随机点击两个广告中的一个广告,当该用户已经弹出过广告则一天内不再弹出。

主函数:

name:cookie名称
urls:广告地址数组
width:宽度
height:高度 

JavaScript代码
  1. function popad(name,urls,width,height)        
  2. {       
  3.     if(!name || !urls) return false;       
  4.     width = width ? width : 300;       
  5.     height = height ? height : 300;       
  6.     var cookieString = new String(document.cookie);       
  7.     var cookieName = name+'=';       
  8.     var pos = cookieString.indexOf(cookieName);       
  9.     if (pos <0){       
  10.         if(rand(10)==1) {       
  11.             url = urls[rand(urls.length)-1];       
  12.             window.open(url,'hello','location=yes,resizable=yes,width='+width+',height='+height);        
  13.             var now = new Date();       
  14.             expiredate = new Date(now.getYear(),now.getMonth(),now.getDate(),23,59,59);       
  15.             document.cookie = name+'=opened;expires='+ expiredate.toGMTString();       
  16.         }       
  17.     }        
  18. }   

 随机函数:

返回的值为1~number的值。 

JavaScript代码
  1. function rand(number) {       
  2.     return Math.floor(Math.random() * number + 1);       
  3. }  

 调用: 

JavaScript代码
  1. adurls = new Array('http://www.163.com','http://www.cnfol.com');       
  2. popad('popad', adurls, 800, 600);   
引用通告地址: 点击获取引用地址
评论: 0 | 引用: 0 | 阅读: 714 | 打印 | 打包
发表评论
昵 称: 密 码:
网 址: 邮 箱:
验证码: 验证码图片 选 项:
头 像:
内 容: