the compact javascript framework
in partnership with mediatemple
Stores and loads an Hash as a cookie using Json format.
Hash. Cookie.js | Stores and loads an Hash as a cookie using Json format. |
Hash. Cookie | Inherits all the methods from Hash, additional methods are save and load. |
Properties | |
save | Saves the Hash to the cookie. |
load | Loads the cookie and assigns it to the Hash. |
Inherits all the methods from Hash, additional methods are save and load. Hash json string has a limit of 4kb (4096byte), so be careful with your Hash size. Creating a new instance automatically loads the data from the Cookie into the Hash. If the Hash is emptied, the cookie is also removed.
name | the key (name) for the cookie |
options | options are identical to Cookie and are simply passed along to it. In addition, it has the autoSave option, to save the cookie at every operation. defaults to true. |
var fruits = new Hash.Cookie('myCookieName', {duration: 3600}); fruits.extend({ 'lemon': 'yellow', 'apple': 'red' }); fruits.set('melon', 'green'); fruits.get('lemon'); // yellow // ... on another page ... values load automatically var fruits = new Hash.Cookie('myCookieName', {duration: 365}); fruits.get('melon'); // green fruits.erase(); // delete cookie
Properties | |
save | Saves the Hash to the cookie. |
load | Loads the cookie and assigns it to the Hash. |
Saves the Hash to the cookie. If the hash is empty, removes the cookie.
Returns false when the JSON string cookie is too long (4kb), otherwise true.
var login = new Hash.Cookie('userstatus', {autoSave: false}); login.extend({ 'username': 'John', 'credentials': [4, 7, 9] }); login.set('last_message', 'User logged in!'); login.save(); // finally save the Hash
Documentation by Aaron Newton & Mootools Developers, generated by NaturalDocs and GeSHi