Reputation: 2642
I have one function use for writing cookie :
function Search_Click() {
$.cookie("urlAction", null);
$.cookie("searchKey", null);
var searchkey = $('#txtsearch').val();
var key = decodeURIComponent(searchkey);
sampleData = "Q=" + key;
if ($.cookie("urlInStock") != null) {
action = "NewSearchIn";
} else {
action = "NewSearch";
}
urlAction = "Pro/" + action + "/";
$.cookie("searchKey", sampleData);
$.cookie("urlActionVal", urlAction);
window.location = "/Pro?tab=2";
}
After Search_Click()
is done, the page will redirect to another page with the cookie that I just registered.
Then if a user click on a link, I would like to delete that cookie.
This is what I tried :
function deleteSearchCookies() {
$.cookie("searchKey", null);
$.cookie("urlActionVal", null);
}
But when I bug in FireBug, the session still exist.
Upvotes: 0
Views: 16730
Reputation: 444
delete like this:
$.cookie(cookieName, null, { expires: -1, path: '/' });
Sorry you need to save it with same path like this:
var date = new Date();
date.setTime(date.getTime() + sameValueForTime);
$.cookie(cookieName, value, { expires: date, path: '/' });
Sometimes firebug bugs and shows that cookie is there when it is deleted, but you can only see it in cookie area not use it.
Upvotes: 1
Reputation: 133413
To delete:
function deleteSearchCookies() {
$.removeCookie("searchKey");
$.removeCookie("urlActionVal");
}
For more info visit question
if you don't want to use plugin, use (its alternate modify as you wish)
//Creates client side cookie
function Cookie(name, value, minutes) {
var expires = "";
if (minutes) {
var date = new Date();
date.setTime(date.getTime() + (minutes * 60 * 1000));
expires = "; expires=" + date.toGMTString();
}
document.cookie = name + "=" + value + expires;
}
function deleteSearchCookies() {
Cookie("searchKey",null,-1);
Cookie("urlActionVal",null,-1);
}
Upvotes: 2
Reputation: 4273
function deleteCookie(name) {
document.cookie = name+'="";-1; path=/';
}
var login = document.getElementById("loginlink");
login.onclick = function() {
deleteCookie("name");
};
Upvotes: 3