• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 444
  • Last Modified:

function delete_cookie()

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
manoj91
Asked:
manoj91
  • 3
  • 2
3 Solutions
 
devicCommented:
last line should be:
document.cookie ="cookieName=; expires=" + expDate.toGMTString();

0
 
devicCommented:
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
 
ZvonkoSystems architectCommented:
The dashes and the year are wrong.

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

0
 
ZvonkoSystems architectCommented:
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
 
ZvonkoSystems architectCommented:
Thanks.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now