Solved

function delete_cookie()

Posted on 2004-10-22
420 Views
Last Modified: 2008-03-17
I would like to have a cooke removed by expiring the cookie.

code.js contains this method:

function delete_cookie()
      {
             var expireDate = new Date ( );              // current date & time
              expireDate.setTime ( expireDate.getTime() - 1 );
              document.cookie date = expireDate.toGMTString();
      }


it is called when the button is clicked in details.htm.  this is the html part of the button:

<input type="button" value="Clear Cookie" onclick="delete_cookie()">

Not sure about the last line in the function.

tks
0
Question by:manoj91
    5 Comments
     
    LVL 25

    Accepted Solution

    by:
    last line should be:
    document.cookie ="cookieName=; expires=" + expDate.toGMTString();

    0
     
    LVL 25

    Assisted Solution

    by:devic
    also you can use date in the past, without create date:

    expires=Thu, 01-Jan-70 00:00:01 GMT

    for example so:
    =======================================
    function deleteCookie(cookieName)
    {
          document.cookie = cookieName + "=; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
    0
     
    LVL 63

    Assisted Solution

    by:Zvonko
    The dashes and the year are wrong.

    Better use this:
         document.cookie=cookieName+"=;expires=Tue, 01 Jan 1970";

    0
     
    LVL 63

    Expert Comment

    by:Zvonko
    Sorry, the correct day is Thu, but it delete the cookie anyway. You can write any day of the week, for example: Mon,
    But to be correct it should be:

         document.cookie=cookieName+"=;expires=Thu, 01 Jan 1970";


    0
     
    LVL 63

    Expert Comment

    by:Zvonko
    Thanks.
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Both jQuery and Mootools offer some nice, easy to use scripts. Mootools is best known for their interactive slideshows and jQuery for their menus, but both have many other uses as well.   jQuery is basically a toolkit with many DOM (http://en.wik…
    This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    856 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now