468,103 Members | 1,252 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,103 developers. It's quick & easy.

Can't delete cookie created in Javascript

83
Hi,

I have the following javascript function which creates a cookie

Expand|Select|Wrap|Line Numbers
  1. function setCookie(c_name,value,expiredays)
  2. {
  3.     var exdate=new Date();
  4.     exdate.setDate(exdate.getDate()+expiredays);
  5.     document.cookie=c_name+ "=" +escape(value)                +((expiredays==null) ? "" : ";expires="
  6.         +exdate.toGMTString());
  7. }
  8.  
it works great and if i call...

setCookie ("A2O_list", ' 0 ', 365)

from within in javascript it puts a cookie on my machine as accepted.

However, now i want to destroy the cookie. I can do this with another javascript function BUT for variuos rreasons i need to do it in ASP.

Now, when i call the standard asp routine to destroy the cookie...

Response.Cookies("A2O_list").Expires=Date - 1
OR
Response.Cookies("A2O_list") = ""

the cookie is NOT destroyed !

Can someone pls explain why ?

Thanks in advance
Jun 26 '08 #1
3 1793
acoder
16,027 Expert Mod 8TB
Is there a reason why you're not using JavaScript to delete the cookie? If you want, you could use ASP to generate JavaScript code to delete the cookie.
Jun 26 '08 #2
TimSki
83
Yes, there is a part of the site (part of the login/register) process where i can not be sure that javascript would be enabled.

It just seems strange that asp annot delete a cookie created in javascript. After all it is just a text file sitting in a folder?
Jun 26 '08 #3
acoder
16,027 Expert Mod 8TB
I'm not sure where ASP stores cookies, but cookies are stored in different places even with JavaScript if you use different browsers.

You can't be sure JavaScript is enabled on any page. If you're going to use ASP to delete cookies, you may as well create them using ASP too.
Jun 26 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by jojowebdev | last post: by
2 posts views Thread by Josh T | last post: by
1 post views Thread by Solo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.