View Single Post
Old 12-11-2012, 11:48 AM   PM User | #10
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Code:
document.write("cookie we have is " + document.cookie + "<br>");
var allcookies = document.cookie;
var cookiearray = allcookies.split(';');
for(var i=0; i<cookiearray.length; i++){ // this is looping through all cookies
var Cookiename = cookiearray[i].split('=')[0]; // ..so these will end up storing the name and value
var Cookievalue = cookiearray[i].split('=')[1]; // ..of whatever is the last cookie
alert("Key is : " +Cookiename + " and Value is : " + Cookievalue);
}

DelCookie(Cookiename); // so this will delete the LAST cookie
UpdateCookie(Cookievalue);

function DelCookie(Cookiename)
{
document.cookie = Cookiename + "=" + " " + ";expires=Fri, 01-Jan-2010 00:00:01 UTC" ;
document.write("cookie we have is " + document.cookie + "<br>");
}

function UpdateCookie(Cookievalue)
{
var loginid = 100020002;
var newCookievalue = Cookievalue.concat(loginid);
document.cookie=Cookiename + "=" + newCookievalue;
document.write("cookie we have is " + document.cookie + "<br>");
alert ("New Value is " +newCookievalue );
}
Also, as mentioned in other posts, you should use a version of a deleteCookie function that allows the specifying of the path, usually as "/". My function would be used like this:
Code:
deleteCookie(someName, '/');
You should wrap your code in CODE tags by clicking the hash (#) key when creating your posts.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Users who have thanked AndrewGSW for this post:
mjosh123 (12-13-2012)