I recently made a function, but it always failed when deleting cookies. I can’t figure out why.
Using $.cookie("name",""); The result is that a new cookie with an empty value is generated.
Use $.cookie("name",null); and the cookie cannot be deleted.
Finally use $.cookie("name",null,{path:"/"}); and finally succeeded.
Maybe it’s a bug in $.cookie. I wonder if the latest version has fixed this bug.
The following are some other $.cookies that are reprinted for later use:
$(function(){
var COOKIE_NAME = 'test_cookie';
//Set cookie through time interval
$('a').eq(0).click(function () {
$.cookie(COOKIE_NAME, 'test', { path: '/', expires: 1 });
return false;
});
// Set cookie, to Period time
$('a').eq(1).click(function() {
var date = new Date();
date.setTime(date.getTime() (1 * 24 * 60 * 60 * 1000));
$.cookie(COOKIE_NAME, 'test', { path: '/', expires: date });
return false;
});
// Get cookie
$('a').eq(2).click(function() {
alert($.cookie(COOKIE_NAME));
return false;
});
//Delete cookie
$('a').eq(3).click(function() {
$.cookie(COOKIE_NAME, null, { path: '/' });
return false;
});
});