设置Cookie

var Site=new Object();

		Site.Cookie={

				_expires:24*3600*1000,

				_domain:'.gdxxb.com',

				set:function(name,value,expires,path,domain){

					expires=new Date(new Date().getTime()+(expires?expires:this._expires));
					document.cookie=name+"="+escape(value)+";expires="+expires.toGMTString()+";path="+(path?path:"/")+";domain="+(domain?domain:this._domain);

				},

				get:function(name){
					var arr=document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
					if(arr!=null) return unescape(arr[2]);
					return null;
				},

				clear:function(name,path,domain){
					if(this.get(name)) document.cookie=name+"=; path="+(path?path:"/")+"; domain="+(domain?domain:this._domain)+"; expires=Fri, 02-Jan-1970 00:00:00 GMT";
				}
		};

		
		var i = 0,
			tempi = Site.Cookie.get("random_");

		if(tempi){


				i = tempi == 1 ? 2 : 1; //三元操作符(在 1 求值为 TRUE 时的值为 2,在 expr1 求值为 FALSE 时的值为 1。)

				Site.Cookie.set("random_",i);


		}else{
				i = Math.round(Math.random()*1)+1, //随机出现1-2

				Site.Cookie.set("random_",i);
				
		}

		
		var str = document.location.href,

			index = str.indexOf("?"),

			temp = "",

			html= "";

			
			

			if(index != -1){

				temp = str.substring(index);
				
			}



			html='<iframe id="mainiframe" src="'+i+'/index.html'+temp+'" scrolling="no" allowtransparency="true" frameborder="0" width="100%" height="100%"></iframe>';

		document.getElementById("iframebox").innerHTML=html;

  

posted @ 2015-06-12 11:20  唸随爱  阅读(295)  评论(0编辑  收藏  举报