javascript 新浪背投广告实现代码

新浪的好多广告代码被广大站长广为流传,大家如果有时间可以去看看,他们的代码都是写出类的,不少的好东西。

今天查看了下新浪的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-600是图片的地址,后面的是链接, 开始日期 结束日期什么的大家参考下就可以了。

以上就是javascript 新浪背投广告实现代码的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » JavaScript 教程