广告轮播代码

广告轮播代码

<script type="text/javascript">
var randoms = {
	ads_codes: ['1','2','3'],
  ------------> 修改为你的广告地址
	ads_weight: [10,10,10],
    ------------> 广告权重

	get_random: function(weight) {
		var s = eval(weight.join('+'));
		var r = Math.floor(Math.random() * s);
		var w = 0;
		var n = weight.length - 1;
		for(var k in weight){w+=weight[k];if(w>=r){n=k;break;}};
		return n;
	},
	init: function() {

		var rand = randoms.get_random(randoms.ads_weight);
		document.write(randoms.ads_codes[rand]);

	}
}
randoms.init();
</script>

弹出时间间隔: ads_timer秒内只弹一次(设置为0则为刷新弹)

<script type="text/javascript">
var randoms = {
	ads_codes: ['1','2','3'],
	ads_weight: [10,10,10],
	ads_timer: 10,
	get_cookie: function(n) {
		var a = document.cookie.match(new RegExp("(^| )" + n + "=([^;]*)(;|$)"));
		if (a != null) return decodeURI(a[2]);
		return null;
	},

	get_random: function(weight) {
		var s = eval(weight.join('+'));
		var r = Math.floor(Math.random() * s);
		var w = 0;
		var n = weight.length - 1;
		for(var k in weight){w+=weight[k];if(w>=r){n=k;break;}};
		return n;
	},
	init: function() {
		if (randoms.get_cookie('XCY_cookie_XCY')) return;

		var rand = randoms.get_random(randoms.ads_weight);
		document.write(randoms.ads_codes[rand]);
		var time = new Date();
		time.setTime(time.getTime() + randoms.ads_timer * 1000);
		document.cookie = 'XCY_cookie_XCY=1;expires=' + time.toGMTString() + ';path=/;';

	}
}
randoms.init();
</script>

发表回复

您的电子邮箱地址不会被公开。