Clearing only specific cookies
How can I clear only two cookies using JavaScript?
I use the below code to set these cookies.
function setCookie(c_name, value, exdays)
{
var exdate = new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value = escape(value) + ((exdays==null) ? "" : ";expires=" + exdate.toUTCString());
document开发者_开发知识库.cookie = c_name + "=" + c_value;
}
A cookie is expired if the Expires parameter value is a date in the past. So just set the value to a date in the past:
function deleteCookie(c_name) {
document.cookie = encodeURIComponent(c_name) + "=deleted; expires=" + new Date(0).toUTCString();
}
use the same function setCookie(c_name,value,exdays), passing exdays = -1. That will set expiry date to yesterday.
精彩评论