![]() |
Delete all cookies?
I currently have a function to expire the cookie when the user logs off. As of now it is not is not expiring the cookie any suggestions?
JS Code:
/// Validate FieldCode:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
In the following code
Code:
document.cookie = allcookies + "=" + cval + "; expires=" + exp.toGMTString();BTW the following only subtracts 1 millisecond, but it is immaterial ;) Code:
exp.setTime(exp.getTime() - 1); // set it to yesterday!BTW I don't think 'button' is a sensible name for a button :) .. I know it's a button! |
This is much easier
Code:
function del_cookie(name) { |
i had some that wouldn't go away. turns out the path has to be "/" sometimes.
it's best to sweep through all keys with and without the path, nulling them all out. |
Quote:
Code:
function deleteCookie ( name, path, domain ) { |
I used mentioned code to modify the cookie value. I was getting two cookies from production server. I have to modify the value of one cookie.
firstly I stored the value & names of the cookies from document.cookie. Then deleted the specific cookie thru your mentioned code function deleteCookie ( name, path, domain ) { document.cookie = name + "=" + ( ( path ) ? ";path=" + path : "") + ( ( domain ) ? ";domain=" + domain : "" ) + ";expires=Fri, 01-Jan-2010 00:00:01 UTC"; } and lastly I modified the value of the cookie as I have stored it in array. Finally creating cookie using document.cookie what it has done is, my cookie file created at (C:\Documents and Settings\Administrator\Cookies) is containing only one cookie could u pls tell me how can I get value updated in this file too. Thanks in advance |
I'm not sure what you are asking: is there a problem with your code, or is there something additional you are trying to achieve?
I notice this code in your first post: Code:
document.cookie="Vln=" + this.value;In which case you probably want a function to set a cookie: Code:
function setCookie( name, value, expires, path, domain, secure ) { |
Hi Andrew,
I am not the same user for whom you provided the solution. I am actually new user, working on cookie value updation. I basically need to create a unique cookie for users browsing through single computer. I have created a subdomain of my client server on other linux server and kept my html pages under the cgi-bin folder of apache server the apache server is running on port 1080. also I have modified my system hostfile (added name of the my subdomain with IP) this is the URL type I am giving at my browser. http://subdomain.domainname.com:port...yhtmlpage.html Now doing so, client server will send cookie with 2 cookies (X=value;Y=value). for making unique cookie I need to update the value of Y cookie with some value I am reading the cookie via document.cookie. then storing both the values in an array. and later seprating the value and name from name value pair stored in array. Once this is done, I am deleting the Y cookie by setting the expiry date and then using document.cookie to create a new Y cookie with new value. Now In doing so when I am printing the old value, deleted value and new value through document.write. everything is happening as intended but when I checked the cookie stored at location (). firstly it was storing both the values (x and y) When I deleted Y, it was having only X in the file but when I created Y with new value. it didnt got reflected. Code snippet is below 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++){ var Cookiename = cookiearray[i].split('=')[0]; var Cookievalue = cookiearray[i].split('=')[1]; alert("Key is : " +Cookiename + " and Value is : " + Cookievalue); } DelCookie(Cookiename); 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 ); } |
Actually, turns out the path has to be "/" sometimes
|
Code:
document.write("cookie we have is " + document.cookie + "<br>");Code:
deleteCookie(someName, '/'); |
Quote:
I set the path to "/" but nothing changed [I mean after updating cookie value, the new value is not getting updated in cookie file (administrator@cgi-bin[1])stored at location C:\Documents and Settings\Administrator\Cookies]:( Can anyone please let me know, which path is it ?? I mean, does it has something to do with the windows path. |
| All times are GMT +1. The time now is 09:44 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.