JS清空当前域名下的所有Cookie

今天项目突然需要用到当用户退出登录时,清楚用户域名下的所有cookie。
不多哔哔,直接上代码:

//清除所有cookie函数
function clearAllCookie() {
var date=new Date();
date.setTime(date.getTime()-10000);
//keys为所要删除cookie的名字
var keys=document.cookie.match(/[^ =;]+(?=\=)/g);
//删除所有cookie
if (keys) {
for (var i = keys.length; i--;)
document.cookie=keys[i]+"=0; expire="+date.toGMTString()+"; path=/";
}
}
//清除所有cookie函数
function clearAllCookie() {
    var date=new Date();
    date.setTime(date.getTime()-10000);
    //keys为所要删除cookie的名字
    var keys=document.cookie.match(/[^ =;]+(?=\=)/g);
    //删除所有cookie
    if (keys) {
        for (var i =  keys.length; i--;)
        document.cookie=keys[i]+"=0; expire="+date.toGMTString()+"; path=/";
        }
}
//清除所有cookie函数 function clearAllCookie() { var date=new Date(); date.setTime(date.getTime()-10000); //keys为所要删除cookie的名字 var keys=document.cookie.match(/[^ =;]+(?=\=)/g); //删除所有cookie if (keys) { for (var i = keys.length; i--;) document.cookie=keys[i]+"=0; expire="+date.toGMTString()+"; path=/"; } }

 

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
Smash the waves would rather get in the way of the reef hill, also not willing to take a step back.
海浪宁可在挡路的礁山上撞得粉碎,也不肯后退一步
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容