Cookie functions

wtbapi 2012-10-22

/*==================================================

Cookiefunctions

==================================================*/

functionsetCookie(name,value,expires,path,domain,secure){

document.cookie=name+"="+escape(value)+

((expires)?";expires="+expires.toGMTString():"")+

((path)?";path="+path:"")+

((domain)?";domain="+domain:"")+

((secure)?";secure":"");

}

functiongetCookie(name){

vardc=document.cookie;

varprefix=name+"=";

varbegin=dc.indexOf(";"+prefix);

if(begin==-1){

begin=dc.indexOf(prefix);

if(begin!=0)returnnull;

}else{

begin+=2;

}

varend=document.cookie.indexOf(";",begin);

if(end==-1){

end=dc.length;

}

returnunescape(dc.substring(begin+prefix.length,end));

}

functiondeleteCookie(name,path,domain){

if(getCookie(name)){

document.cookie=name+"="+

((path)?";path="+path:"")+

((domain)?";domain="+domain:"")+

";expires=Thu,01-Jan-7000:00:01GMT";

}

}

相关推荐