// 获取cookie
function getCookie (cookieName) {
// name=lxw;age=18
let start = document.cookie.indexOf(cookieName)
if (start > -1) {
start = start + cookieName.length + 1;
let end = document.cookie.indexOf(';', start)
console.log('', 'color: #40fff2', end);
end = end > -1 ? end : document.cookie.length
return unescape(document.cookie.substring(start, end))
} else {
return undefined
}
}
// 设置cookie
function setCookie(cookieName, value, days = 1) {
const date = new Date()
date.setTime(date.getTime() + days * 3600 * 24 * 1000)
document.cookie = `${cookieName}=${escape(value)}; expires=${ date.toGMTString() }; path=/; domian=.kuwo-inc.com`
}
// 删除cookie
const delCookie = (cookie_name) => {
const exp = new Date();
exp.setTime(exp.getTime() - 1);
const val = getCookie(cookie_name);
if (val != null) {
document.cookie = cookie_name + '=' + val + ';expires=' + exp.toGMTString() + ';path=/;domain=.kuwo.cn'
}
};
浏览器设置,读取,删除cookie方法
最新推荐文章于 2024-05-27 08:43:25 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)