打赏

JS设置cookie、读取cookie、删除cookie

export  function setCookie(c_name, value) {

var exp = new Date(); exp.setTime(exp.getTime() + 100*24*60*60*1000);
document.cookie = c_name + "=" + escape(value)+"; domain=.zhijiaxing.net;expires="+ exp.toGMTString();
};

export function getCookie(c_name) {
var arr, reg = new RegExp("(^| )" + c_name + "=([^;]*)(;|$)");
if (arr = document.cookie.match(reg))
return unescape(arr[2]);
else
return "";
};

export function delCookie(c_name) {
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval = getCookie(c_name);
if (cval != null)
document.cookie = c_name + "=" + cval + ";expires=" + exp.toGMTString();
}

 

修改域:

document.cookie="example=1; max-age=0; domain=www.test.com;path=/;"

posted @ 2019-11-14 14:20  刘奇云  阅读(290)  评论(0编辑  收藏  举报