function cookieToJson(str) {
let cookieArr = str.split(";");
let obj = {}
cookieArr.forEach((i) => {
let arr = i.split("=");
obj[arr[0]] =arr[1];
});
return obj
}
function writeCookie(name, value, hours)
{
var expire = "";
if(hours != null)
{
expire = new Date((new Date()).getTime() + hours * 3600000);
expire = "; expires=" + expire.toGMTString();
}
document.cookie = name + "=" + escape(value) + expire;
}
var cks = cookieToJson(document.cookie);
for(var p in cks) {
console.log(p,cks[p])
writeCookie(p,cks[p])
}
html javascript 设置cookie永不过期
最新推荐文章于 2024-09-19 08:45:00 发布
关键词由CSDN通过智能技术生成