xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

multi cookie & read bug

js cookie

multi cookie & read bug


document.cookie;

// "access_token_test=eyJhbGciOiJIUzI1NiJ9.eyJyb2xlIjoiRGV2ZWxvcGVyIiwiZXhwaXJlZCI6MTU0MDAxNTg4MjgwMSwiYXV0aCI6WyJwdWJsaXNoIl0sInVzZXJfbmFtZSI6Inh4eHgiLCJ0b2tlbl9rZXkiOiJhY2Nlc3NfdG9rZW5fdGVzdCIsImVtYWlsIjpudWxsfQ.HZUwdyOU3rqpr_bkQZfMdlDFwY7iC8fQKlqxRTCc5Ek; access_token_prod=eyJhbGciOiJIUzI1NiJ9.eyJyb2xlIjoiQWRtaW4iLCJleHBpcmVkIjoxNTQwMDE2MDkzODA5LCJhdXRoIjpbInB1Ymxpc2giLCJvcGVyYXRpb24iLCJhY2NvdW50Il0sInVzZXJfbmFtZSI6ImFkbWluIiwidG9rZW5fa2V5IjoiYWNjZXNzX3Rva2VuX3Byb2QiLCJlbWFpbCI6bnVsbH0.qzDBwIld35c62ip-SG7jDz4vzqCOEyLyeux9dVLVxmU"


JWT

https://jwt.io/introduction/


https://github.com/js-cookie/js-cookie
https://www.npmjs.com/package/js-cookie

https://www.w3schools.com/js/js_cookies.asp


read bug

https://github.com/js-cookie/js-cookie

$ npm i js-cookie

$ npm i -S js-cookie


cookie getter

a more simple cookie getter method!

https://www.w3schools.com/js/js_cookies.asp


function getCookie(cname) {
    var name = cname + "=";
    var decodedCookie = decodeURIComponent(document.cookie);
    var ca = decodedCookie.split(';');
    for(var i = 0; i <ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') {
            c = c.substring(1);
        }
        if (c.indexOf(name) == 0) {
            return c.substring(name.length, c.length);
        }
    }
    return "";
}


npm bug

posted @ 2018-10-19 14:17  xgqfrms  阅读(253)  评论(4编辑  收藏  举报