Can't delete cookie created in Javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TimSki
    New Member
    • Jan 2008
    • 83

    Can't delete cookie created in Javascript

    Hi,

    I have the following javascript function which creates a cookie

    [CODE=javascript]function setCookie(c_nam e,value,expired ays)
    {
    var exdate=new Date();
    exdate.setDate( exdate.getDate( )+expiredays);
    document.cookie =c_name+ "=" +escape(value) +((expiredays== null) ? "" : ";expires="
    +exdate.toGMTSt ring());
    }
    [/CODE]
    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.Cookie s("A2O_list").E xpires=Date - 1
    OR
    Response.Cookie s("A2O_list") = ""

    the cookie is NOT destroyed !

    Can someone pls explain why ?

    Thanks in advance
    Last edited by acoder; Jun 26 '08, 10:46 AM. Reason: Added [code] tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    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.

    Comment

    • TimSki
      New Member
      • Jan 2008
      • 83

      #3
      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?

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        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.

        Comment

        Working...