Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modify document.cookie in Chrome console not working

Can I modify document.cookie in the console of Chrome Developer Tools?

My current cookie string was like:

"coldcookie="

It seems it just doesn't work if I run this code below:

document.cookie = document.cookie + "; newcookie=something"

The document.cookie wouldn't change at all.

Update: I found that if I run:

document.cookie = "newcookie"

It actually add a "newcookie" in the cookie string like:

"oldcookie=; newcookie"

Shouldn't that clear the current cookie string?

It does the same thing in IE. So I think there must be some rule there. Any ideas?

like image 423
bigbearzhu Avatar asked Jun 07 '13 03:06

bigbearzhu


1 Answers

Cookies are set to expire, since we can't really "delete" them, we just force them to expire with a past date.

function deleteCookie(name) {
    document.cookie = name + '=;expires=Thu, 05 Oct 1990 00:00:01 GMT;';
};

deleteCookie('newcookie')
like image 134
Seth Avatar answered Nov 10 '22 08:11

Seth