Reputation: 3042
is it possible to rewrite the value of stored cookie? If so How to do that?
My exact case is,
I have created a cookie with some PATH(frm user,which i don know probably). I have to rewrite the value of this cookie somewhere else. I can just create a cookie wit same name but the problem here is i don know the PATH value.
Any help would be most welcome Thanks.
Upvotes: 2
Views: 4746
Reputation: 5358
From the DOC
If the user agent receives a new cookie with the same cookie-name, domain-value, and path-value as a cookie that it has already stored,the existing cookie is evicted and replaced with the new cookie. Notice that servers can delete cookies by sending the user agent a new cookie with an Expires attribute with a value in the past.
So, What @Royi Namir has posted is the solution. Coz there is no specific way to rewrite cookie other than setting it again.
Refer this answer in SO regarding getting path info of a stored cookie
Upvotes: 2
Reputation: 148624
you can save cookie like that :
function setCookie(name, value, expires) {
document.cookie = name + "=" + escape(value) + "; path=/" + ((expires == null) ? "" : "; expires=" + expires.toGMTString());
Upvotes: 1