1

i create a cookie and use it like this.inside a document.ready

 document.cookie = $('#rdb1').attr("id");
 check = document.cookie.split(';');
 flag = check[0];

But unable to erase cookies.I found this function.

function Delete_Cookie( name, path, domain ) 
{
   if ( Get_Cookie( name ) )
   document.cookie=name+"="+((path) ? ";path="+path:"")+((domain)?";domain="+domain:"") +
                                   ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

on javascript - delete cookie.But unable to use this function in my situation.Any idea how to deal with this.Thanks.

Community
  • 1
  • 1
4b0
  • 21,981
  • 30
  • 95
  • 142

2 Answers2

1

If you are using jQuery cookie, you might want to try just setting the cookie to null, like this:

$.cookie("name", null);

There was a similar question about it found here: jquery, delete cookies .

Note: when deleting a cookie, you must pass the exact same path, domain and secure options that were used to set the cookie.

To set the path for a cookie, you could use something like this:

$.cookie("name", null, { path: '/' });
Community
  • 1
  • 1
summea
  • 7,390
  • 4
  • 32
  • 48
  • what a `name` stands for in my situation? – 4b0 Feb 26 '12 at 05:38
  • In your case, "name" is whatever your cookie's name is. :) – summea Feb 26 '12 at 05:39
  • I put a link to jQuery cookie (https://github.com/carhartl/jquery-cookie) in the answer, as well, just in case you need to get the `jquery.cookie.js` file to make this work! – summea Feb 26 '12 at 05:45
  • i modify the question.i use cookies like this.Again i am confusing what is the name stands for? – 4b0 Feb 26 '12 at 05:48
  • It is the name you want to use for your cookie. It's easier to use the jQuery cookie plugin for creating the cookie. To create a cookie, you would just write something like: `$.cookie('the_cookie', 'the_value');` In that example, the cookie's name is `'the_cookie'`. Then... to delete that cookie... you would just use `$.cookie('the_cookie', null);` – summea Feb 26 '12 at 05:53
0

I use this jquery plugin (very simple =P).

https://github.com/carhartl/jquery-cookie

Brian Minnich
  • 402
  • 2
  • 4