W3cubDocs

/Dojo

dojo/cookie

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});
});

Methods

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.

© 2005–2017 JS Foundation
Licensed under the AFL 2.1 and BSD 3-Clause licenses.
http://dojotoolkit.org/api/1.10/dojo/cookie.html