August 2008
Mon Tue Wed Thu Fri Sat Sun
« Jul   Sep »
 123
45678910
11121314151617
18192021222324
25262728293031

Day August 22, 2008

More about jQuery cookies

When working with jQuery’s cookie plug in, it’s important to keep in mind the path that is going to be used.

On a web site’s default.html page, the path will be set to /, but one or two directories down, the cookie’s path will be /dir/subdir.

I’ve gotten around this by encapsulating the information that I need to store into JavaScript objects that can be easily deserialized and serialized by JSON2.js and building in a Save() and Load() function.

Save() looks something like:

MyStorageObject.prototype.Save = function() {
this.ErrorMessage = undefined;
$.cookie(this.$name, this.toJsonString(), { path: '/' });
}

The Load() method is a little bit more cumbersome, but it basically goes through the properties of the object and loads them from the JSON object.

This site is protected with Urban Giraffe's plugin 'HTML Purified' and Edward Z. Yang's Powered by HTML Purifier. 226 items have been purified.