dojo/cookie (version 1.10)

Summary

Get or set a cookie.

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

Usage

cookie(name,value,props);
Parameter Type Description
name String

Name of the cookie

value String
Optional

Value for the cookie

props Object
Optional

Properties for the cookie

Returns:undefined

See the dojo/cookie reference documentation for more information.

Examples

Example 1

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

require(["dojo/cookie", "dojo/json"], function(cookie, json){
    cookie("configObj", json.stringify(config, {expires: 5 }));
});

Example 2

de-serialize a cookie back into a JavaScript object:

require(["dojo/cookie", "dojo/json"], function(cookie, json){
    config = json.parse(cookie("configObj"));
});

Example 3

delete a cookie:

require(["dojo/cookie"], function(cookie){
    cookie("configObj", null, {expires: -1});
});

Method Summary

  • isSupported() Use to determine if the current browser supports cookies or not.

Methods

isSupported()
Defined by dojo/cookie

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.

Error in the documentation? Can’t find what you are looking for? Let us know!