首页  >  文章  >  web前端  >  javascript 新浪背投广告实现代码_广告代码

javascript 新浪背投广告实现代码_广告代码

WBOY
WBOY原创
2016-05-16 18:50:251257浏览

今天查看了下新浪的js代码,发现一个背投的广告类代码,不论是从学习角度还是使用角度都是不错的,但发现了一个问题,会被屏蔽的。
下面是具体的js类代码

复制代码 代码如下:

/*
轮播背投类 RotatorPB v3.1
Update by Dakular 2008-8-25
格式:new RotatorPB(广告数组)
说明:第一次访问随机出现,以后访问顺序轮播;自动过滤过期广告;cookie时间24小时;商业广告数量不足时不显示
*/
if(typeof(RotatorPB)!='function'){
    var RotatorPB=function (rad){
        this.ary = new Array();
        this.date = new Date();
        this.w = rad.width;
        this.h = rad.height;
        this.num = rad.num;
        this.o = rad.length;
        this.id = RotatorPB.id++;
        this.m = 'rpb_'+this.id;
        this.n = new Array();
        this.L = new Date();
        this.e = 0;
        var f;
        var D = false;
        var nn = 0;
        //过滤无效广告
        for(var i=0; i            var start = RotatorPB.strToDate(rad[i][2].replace('','').replace('',''));
            var end = RotatorPB.strToDate(rad[i][3].replace('','').replace('',''),true);
            if(this.date>start && this.date                this.ary.push([rad[i][0], rad[i][1], rad[i][4]]);
            }
        }
        this.o = this.ary.length;
        //取id
        for(var i=0;i            f=this.m+'_'+(i+1);
            g=RotatorPB.G(f);
            if(g!=''){
                this.n[i]=g;
                D=true;
            }else {
                this.n[i]=0;
            }
        }
        if(!D){
            var r=Math.ceil(Math.random()*this.o);
            var t=this.m+'_'+r;
            RotatorPB.S(t,this.L.getTime(),1440);
            this.e=r;
            if(this.o==1){RotatorPB.S('s_dl',r,1440);}
            //return r;
        }else {
            var R=this.n.join(',').split(',');
            var k=R.sort();
            var max=Number(k[k.length-1]);
            var min=Number(k[0]);
            var F;
            for(var i=0;i                if(max==this.n[i]){
                    F=i+1;
                    break;
                }
            }
            if(typeof(F)!='undefined'){
                G=this.m+'_'+F;
                H=Number(RotatorPB.G(G));
                I=F%this.o+1;
                J=this.m+'_'+I;
                RotatorPB.S(J,this.L.getTime(),1440);
                if(this.o==1){
                    I=-RotatorPB.G('s_dl');
                    if(I==0){I=1;RotatorPB.S('s_dl',1,1440);}
                    RotatorPB.S('s_dl',I,1440);
                }
                this.e=I;
                //return I;
            }
        }
        //Show AD
        if(this.e==0 || this.ary.length==0) return; //如果没有广告则不显示
        if(this.e==-1) return; //当只有一个广告时:始终显示第一个/奇数次刷新显示
        var n = this.e-1;
        var btsrc = this.ary[n][0];
        var bturl = this.ary[n][1];
        var bttype = btsrc.substring(btsrc.length-3).toLowerCase();
        if(bttype=='.js'){ //js
            document.write('


具体的调用代码:
复制代码 代码如下:




上面的beitou.jpg是图片的地址,后面的是链接, 开始日期 结束日期什么的大家参考下就可以了。
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn