最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - $.removeCookie is not deleting cookie in Chrome - Stack Overflow

programmeradmin3浏览0评论

$.removeCookie is not deleting cookie in Chrome.

Please refer the below attachment of screenshot. The screenshot is taken from the Chrome settings -> All Cookie and site data.

The above screenshot is clearly showing that one cookie(name : !Proxy!proxyJSESSIONID, and path : /stockquote/rest/auth) is available. But when

$.removeCookie('!Proxy!proxyJSESSIONID', { path: '/stockquote/rest/auth'});

code is executed it is returning false and not deleting the cookie.

I am using jQuery Cookie Plugin v1.4.1.

$.removeCookie is not deleting cookie in Chrome.

Please refer the below attachment of screenshot. The screenshot is taken from the Chrome settings -> All Cookie and site data.

The above screenshot is clearly showing that one cookie(name : !Proxy!proxyJSESSIONID, and path : /stockquote/rest/auth) is available. But when

$.removeCookie('!Proxy!proxyJSESSIONID', { path: '/stockquote/rest/auth'});

code is executed it is returning false and not deleting the cookie.

I am using jQuery Cookie Plugin v1.4.1.

Share Improve this question asked Dec 23, 2015 at 11:22 SuvonkarSuvonkar 2,46013 gold badges34 silver badges44 bronze badges
Add a ment  | 

5 Answers 5

Reset to default 6

To delete a cookie with jQuery set the path value to null:

$.removeCookie('filter', { path: '/' });

To delete cookie, set it's value for null

$.cookie("!Proxy!proxyJSESSIONID", null, { path: '/stockquote/rest/auth' });

And it would be deleted

Finally I have found an alternative.

$.cookie('!Proxy!proxyJSESSIONID', '', { expires: -1, path: '/stockquote/rest/auth'});
  1. Setting the value as blank('') and
  2. Set one additional option expires : -1

But $.removeCookie is not working.

Always use path while setting cookies. By default cookies are saved as per pages

//Set value to cookie
$.cookie('key', 'value', { path: '/your/path'});

//remove value from cookie
$.removeCookie('key', { path: '/your/path' });
   document.querySelector('#btn3').addEventListener('click', userExit);
    //click func for (unlogin) dellite cookie.
    function userExit(e) {
        e.preventDefault();
        let cookie = document.cookie.split('; ');
        let cookieObject = {};
        for (var i = 0; i < cookie.length; i++) {
            var cookieArr = cookie[i].split('=');
            cookieObject[cookieArr[0]] = cookieArr[1];
        };
        let expDate = new Date();
        expDate.setTime(expDate.getTime() - 1000);
        for (let cookie in cookieObject) {
            let expires = expDate.toGMTString();
            document.cookie = cookie + '=' + '; expires=' + expires + '; path=/';
        };
        location.reload();
    };
发布评论

评论列表(0)

  1. 暂无评论