Saturday, April 14, 2007

Prototype Library that helps store JSON data in cookies

Lalit Patel wrote JavaScript Library that helps to use JSON to store data in cookies.
The nice library is built on top of Prototype and gives you a simple API to put and get JSON values into cookies.

Full information and download:
Yummy JSON Cookies (using Prototype)

Code Example:
var jar = new CookieJar({
expires:3600, // seconds
path: '/'
});

var dog = {name: 'Jacky', breed: 'Alsatian', age:5};

jar.put('mydog', dog);
mydog = jar.get('mydog');

alert("My dog's name is " + mydog.name);
alert("He is " + mydog.age + " years old");
alert("He is an " + mydog.breed);

Enjoy :-)

No comments: