js 清除 localStorage 和 cookies,

但是清除cookies,  页面必须在jquery.js下面, 引入jquery.cookie.js

path cookie值的保存路径,默认与创建页的路径一致

expires 是有限日期,单位是天

document.domain是当前域名

 

// 清空所有的localStorage
localStorage.clear();

// 清空所有cookies
clearAllCookie();
function clearAllCookie() {
    var keys=document.cookie.match(/[^ =;]+(?=\=)/g);
    if (keys) {
        for (var i =  keys.length; i--;)
                document.cookie = keys[i] + '=0;path=/;expires=' + new Date(0).toUTCString();// 清除当前域名路径的有限日期
                document.cookie = keys[i] + '=0;path=/;domain=' + document.domain + ';expires=' + new Date(0).toUTCString();// Domain Name域名 清除当前域名的
                document.cookie = keys[i] + '=0;path=/;domain=baidu.com;expires=' + new Date(0).toUTCString();// 清除一级域名下的或指定的
            }
        }

jq清除该站点的所有cookie

 

相关文章:

  • 2021-04-05
  • 2022-12-23
  • 2021-09-21
  • 2021-04-27
  • 2022-12-23
  • 2022-12-23
  • 2022-01-18
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-27
  • 2022-01-28
  • 2021-11-27
相关资源
相似解决方案