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.

2 Answers 2

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: '/' });
Sign up to request clarification or add additional context in comments.

5 Comments

what a name stands for in my situation?
In your case, "name" is whatever your cookie's name is. :)
I put a link to jQuery cookie (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!
i modify the question.i use cookies like this.Again i am confusing what is the name stands for?
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);
0

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.