美文网首页
HookCookie

HookCookie

作者: 还是那个没头脑 | 来源:发表于2020-11-28 19:32 被阅读0次
    (function() {
        'use strict';
        var cookie_cache = document.cookie;
        Object.defineProperty(document, 'cookie', {
            get: function() {
                console.log(cookie_cache);
                return cookie_cache;
            },
            set: function(val) {
                debugger;
                var cookie = val.split(";")[0];
                var ncookie = cookie.split("=");
                var flag = false;
                var cache = cookie_cache.split(";");
                cache = cache.map(function(a){
                    if (a.split("=")[0] === ncookie[0]){
                        flag = true;
                        return cookie;
                    }
                    return a;
                })
                cookie_cache = cache.join(";");
                if (!flag){
                    cookie_cache += cookie + ";";
                }
            },
        });
    
    })();
    
    

    相关文章

      网友评论

          本文标题:HookCookie

          本文链接:https://www.haomeiwen.com/subject/wxecwktx.html