function readCookie (name) {
var nameEQ=name+"=";
var ca=document.cookie.split(';');
for(var i=0;i<ca.length;i++){
var c=ca[i];var idx=0;
while(c.charAt(idx)==' ')
idx++;
if(idx>0)
c=c.substr(idx);
if(c.indexOf(nameEQ)==0)
return c.substr(nameEQ.length);
}
return null;
}
function deleteCookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = readCookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
function setCookie(name, value)
{
var expdate = new Date();
var argv = setCookie.arguments;
var argc = setCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
if(expires!=null) expdate.setTime(expdate.getTime() + ( expires ));
document.cookie = name + "=" + escape (value) +((expires == null) ? "" : ("; expires="+ expdate.toGMTString()))
+((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
+((secure == true) ? "; secure" : "");
}
javascript操作coockie
最新推荐文章于 2024-02-17 19:51:30 发布