Functiondojo.cookie

dojo.require("dojo.cookie");
defined in dojo/cookie.js

If one argument is passed, returns the value of the cookie For two or more arguments, acts as a setter.

Usage

function (/*String*/ name, /*String?*/ value, /*dojo.__cookieProps?*/ props) (view source)
parametertypedescription
nameStringName of the cookie
valueStringOptional. Value for the cookie
propsdojo.__cookiePropsOptional. Properties for the cookie
fieldtypedescription
.domainStringOptional. The domain to use for the cookie.
.expiresDate|String|NumberOptional. If a number, the number of days from today at which the cookie will expire. If a date, the date past which the cookie will expire. If expires is in the past, the cookie will be deleted. If expires is omitted or is 0, the cookie will expire when the browser closes. << FIXME: 0 seems to disappear right away? FF3.
.pathStringOptional. The path to use for the cookie.
.secureBooleanOptional. Whether to only send the cookie on secure connections

Examples

Example 1

set a cookie with the JSON-serialized contents of an object which will expire 5 days from now:

dojo.cookie("configObj", dojo.toJson(config), { expires: 5 });

Example 2

de-serialize a cookie back into a JavaScript object:

var config = dojo.fromJson(dojo.cookie("configObj"));

Example 3

delete a cookie:

dojo.cookie("configObj", null, {expires: -1});

FunctionsBack to top

Use to determine if the current browser supports cookies or not. Returns true if user allows cookies. Returns false if user doesn't allow cookies.