Созонов Алексей

Веб-разработчик

Set/Unset cookie jQuery

09.08.2015

Скачать

Записываем в cookie

$.cookie("test", 1);

Удаляем

$.removeCookie("test");

Задаем время хранения cookie

$.cookie("test", 1, { expires : 10 });

Добавляем опции

$.cookie("test", 1, {
   expires : 10,           //expires in 10 days

   path    : '/',          //The value of the path attribute of the cookie 
                           //(default: path of page that created the cookie).

   domain  : 'jquery.com',  //The value of the domain attribute of the cookie
                           //(default: domain of page that created the cookie).

   secure  : true          //If set to true the secure attribute of the cookie
                           //will be set and the cookie transmission will
                           //require a secure protocol (defaults to false).
});

Получаем значение

var cookieValue = $.cookie("test");
var cookieValue = $.cookie("test", { path: '/foo' });
#JQuery‏‎