昨天写了一个关于JS的cookie操作的页面,弄了好久,现在赶紧收藏下:
//===============================================
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();
}
//===============================================
function jsGetCookie(name){//获得Cookie的原始值
var cookStringArray = window.document.cookie.split("; ");
for(var i=0; i<cookStringArray.length;i++){
var cookieInfo = cookStringArray[i].split("=");
if(name == cookieInfo[0]) {
return unescape(cookieInfo[1]);
}
}
return null;
}
//=================================================
function isSetCookie(){//js检查Cookie的函数
bannerCenter = jsGetCookie('bannerCenter');
if (bannerCenter!=null && bannerCenter!=""){
return true;
} else {
SetCookie('bannerCenter',1,3600*24);
}
}
浙公网安备 33010602011771号