$.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 badges5 Answers
Reset to default 6To 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'});
- Setting the value as blank('') and
- 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();
};