Javascript Cookie Library with jQuery bindings and JSON support
Библиотека работы с куками с поддержкой JSON
http://code.google.com/p/cookies/
Разработчик: James Auldridge
Текущая версия на момент написания статьи: 2.2.0
Дата: 06 Января 2010
Примеры использования:
// установка куки
$.cookies.set( 'sessid', 'dh3tr62fghe' ); //кука с именем 'sessid' теперь существует и содержит значение 'dh3tr62fghe'
// получение куки
var sessid = $.cookies.get( 'sessid' ); //переменная 'sessid' теперь содержит значение 'dh3tr62fghe'
// удаление куки
$.cookies.del( 'sessid' ); //кука с именем 'sessid' была удалена.
// тест
if( $.cookies.test() )
{
//browser is accepting cookies
}
//JSON
var jimData = {id: 1, name: 'jim'};
$.cookies.set( 'userdata', jimData ); //A cookie by the name 'userdata' now exists with a serialized copy of jimData
var userData = $.cookies.get( 'userdata' ); //A variable named 'userData' now holds the unserialized object--should be identical to the variable 'jimData'
//jQuery Extensions
$( 'input.store' ).cookify(); //Inputs with class of 'store' are written to a cookie named after the input
$( 'input.store' ).cookieFill(); //Inputs with class of 'store' are filled with the value of cookies with matching names
$( 'input.store' ).cookieBind(); //Inputs with class of 'store' are filled with the value of cookies with matching names and whenever they change the cookie will be updated