Cookie.js

A cookie reader/creator

Credits

based on the functions by Peter-Paul Koch (http://quirksmode.org)

Summary
Cookie.jsA cookie reader/creator
CookieClass for creating, getting, and removing cookies.
Properties
setSets a cookie in the browser.
getGets the value of a cookie.
removeRemoves a cookie from the browser.

Cookie

Class for creating, getting, and removing cookies.

Summary
Properties
setSets a cookie in the browser.
getGets the value of a cookie.
removeRemoves a cookie from the browser.

Properties

set

Sets a cookie in the browser.

Arguments

keythe key (name) for the cookie
valuethe value to set, cannot contain semicolons
optionsan object representing the Cookie options.  See Options below.  Default values are stored in Cookie.options.

Options

domainthe domain the Cookie belongs to.  If you want to share the cookie with pages located on a different domain, you have to set this value.  Defaults to the current domain.
paththe path the Cookie belongs to.  If you want to share the cookie with pages located in a different path, you have to set this value, for example to “/” to share the cookie with all pages on the domain.  Defaults to the current path.
durationthe duration of the Cookie before it expires, in days.  If set to false or 0, the cookie will be a session cookie that expires when the browser is closed.  This is default.
secureStored cookie information can be accessed only from a secure environment.

Returns

An object with the options, the key and the value.  You can give it as first parameter to Cookie.remove.

Example

Cookie.set('username', 'Harald'); // session cookie (duration is false), or ...
Cookie.set('username', 'JackBauer', {duration: 1}); // save this for 1 day

get

Gets the value of a cookie.

Arguments

keythe name of the cookie you wish to retrieve.

Returns

The cookie string value, or false if not found.

Example

Cookie.get("username") //returns JackBauer

remove

Removes a cookie from the browser.

Arguments

cookiethe name of the cookie to remove or a previous cookie (for domains)
optionsoptional. you can also pass the domain and path here.  Same as options in Cookie.set

Examples

Cookie.remove('username') //bye-bye JackBauer, cya in 24 hours
 
var myCookie = Cookie.set('username', 'Aaron', {domain: 'mootools.net'}); // Cookie.set returns an object with all values need to remove the cookie
Cookie.remove(myCookie);
Sets a cookie in the browser.

Documentation by Aaron Newton & Mootools Developers, generated by NaturalDocs and GeSHi