Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

function delete_cookie()

Posted on 2004-10-22
5
Medium Priority
?
442 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
Comment
Question by:manoj91
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 25

Accepted Solution

by:
devic earned 1200 total points
ID: 12379164
last line should be:
document.cookie ="cookieName=; expires=" + expDate.toGMTString();

0
 
LVL 25

Assisted Solution

by:devic
devic earned 1200 total points
ID: 12379178
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
Zvonko earned 400 total points
ID: 12389265
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
ID: 12389297
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
ID: 12405312
Thanks.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

609 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