昨天写了一个关于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);
}
}

 

 

 

 

相关文章:

  • 2021-05-26
  • 2021-12-25
  • 2021-06-10
  • 2021-07-15
  • 2021-09-09
  • 2021-05-25
猜你喜欢
  • 2021-12-29
  • 2021-11-29
  • 2022-12-23
  • 2021-12-04
  • 2021-12-21
相关资源
相似解决方案