谷歌浏览器保存和设置Cookies和localStorage

前言

这个主要是用来处理一些网站的单点登录,如果只有1个账号,多台电脑登录时会互相踢掉,就可以用这种方案。

1、打开浏览器,贴上你要登录的界面网址

2、打开F12功能,点击Console

保存cookie

1、把下面代码跳到控制台

var cookies = document.cookie
var content = `function setCookie(cookie_str){\n\tvar str_list = cookie_str.split(';'); \n\tfor (var key of str_list){\n\t\tdocument.cookie = key;\n\t} \n}`
content += `\nsetCookie('${cookies}')\n`

for(var i = 0;i < localStorage.length;i++){
    var key=localStorage.key(i);
    var value = localStorage.getItem(key)
    content += `localStorage.setItem('${key}','${value}');\n`
}
console.log(`--------复制以下信息------------------\n${content}`)

2、控制台会出来设置的代码,如下所示:

--------复制以下信息------------------
function setCookie(cookie_str){
    var str_list = cookie_str.split(';'); 
    for (var key of str_list){
        document.cookie = key;
    } 
}
setCookie('Authorization=rBk2BAzU2vHyNeKKZfLk_KcPKwMRAMYJjSt3N8lh3xrcHMXMLH4jqUu48E5BBZzXJ2vr-e8_Z8CG-M74Ql-CRDtKKTqh1PCNq_wr6M7_JYey5_bVM0Awz91LQZXh7DvOqDCmWtfZ15NbHVD1Hip6ng; refresh_token=rBk2BAzU2vHyNeKKZfLk_CoQ4seYX-b6dn1Rnt1Spzu6B789zNzuBgW2QEDjDcjRPNW7dtK49EhYlP0XOOWgoCa-xR1D1ROKtcpbKc6UdMI')
localStorage.setItem('tempToken','bearer rBk2BAzU2vHyNeKKZfLk_KcPKwMRAMYJjSt3N8lh3xrcHMXMLH4jqUu48E5BBZzXJ2vr-e8_Z8CG-M74Ql-CRDtKKTqh1PCNq_wr6M7_JYey5_bVM0Awz91LQZXh7DvOqDCmWtfZ15NbHVD1Hip6ng ? 1655796332706');
localStorage.setItem('token','bearer rBk2BAzU2vHyNeKKZfLk_KcPKwMRAMYJjSt3N8lh3xrcHMXMLH4jqUu48E5BBZzXJ2vr-e8_Z8CG-M74Ql-CRDtKKTqh1PCNq_wr6M7_JYey5_bVM0Awz91LQZXh7DvOqDCmWtfZ15NbHVD1Hip6ng');

设置cookie

1、把打印出的代码贴到其他电脑的控制台

--------复制以下信息------------------
function setCookie(cookie_str){
    var str_list = cookie_str.split(';'); 
    for (var key of str_list){
        document.cookie = key;
    } 
}
......

2、点击回车,刷新页面

你可能感兴趣的:(谷歌浏览器保存和设置Cookies和localStorage)