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.

Menu