一聚教程网:一个值得你收藏的教程网站

热门教程

javascript cookie类(删除cookie,获取,设置cookie值

时间:2022-11-14 22:02:59 编辑:袖梨 来源:一聚教程网

function issetcookie(){//网页特效检查cookie的函数
bannercenter = 网页特效getcookie('bannercenter');
if (bannercenter!=null && bannercenter!=""){
return true;
} else {
setcookie('bannercenter',1,3600*24);
}
}


//===============================================
function jsgetcookie(name){//获得cookie的原始值
var cookstringarray = window.document.cookie.split("; ");
for(var i=0; i var cookieinfo = cookstringarray[i].split("=");
if(name == cookieinfo[0]) {
return unescape(cookieinfo[1]);
}
}
return null;
}

function setcookie(name, value){//设定cookie值
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 * 1000 ));
document.cookie = name + "=" + escape (value) +((expires == null) ? "" : ("; expires="+ expdate.togmtstring()))
+((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
+((secure == true) ? "; secure" : "");
}
//=============================================
function delcookie(name){//删除cookie
var exp = new date();
exp.settime (exp.gettime() - 1);
var cval = getcookie (name);
document.cookie = name + "=" + cval + "; expires="+ exp.togmtstring();

}

热门栏目