Cookie Manager
Updated on Sat 29 Oct: Removed dependency on Prototype's $ function.
A simple object to encapsulate cookie handling.
Download:
Features
- Get, set and clear cookies.
- Also provides a means of using Internet Explorer's proprietary userData behaviour for larger, persistent storage.
Usage
Initialisation of a CookieManager object:
var manager = new CookieManager();
var manager = new CookieManager({shelfLife:30});
Using IE's userData behaviour instead of cookies in IE:
var manager = new CookieManager({userData:true});
Using the cookie manager:
manager.setCookie("myCookie", aVariable);
var cookieValue = manager.getCookie("myCookie");
manager.clearCookie("myCookie");
Dependencies
None.
Reference
| Method | Kind | Argument | Description |
|---|---|---|---|
| CookieManager([options]) | constructor |
|
Creates an instance of this object using the given options, if any |
| getCookie(cookieName) | instance |
|
Returns the value of the specified cookie if it exists, null otherwise |
| setCookie(cookieName, value) | instance |
|
Stores the given value in a cookie with the given name |
| clearCookie(cookieName) | instance |
|
Clears the cookie with the given name |
The options argument object
| Property | Type | Default | Description |
|---|---|---|---|
| shelfLife | Number | 365 | How long should the cookie expire after |
| userData | Boolean | false |
When running on Internet Explorer, should its proprietary userData behaviour be used for storage instead of cookies |