Status: Draft
Version: 0.9

dojo.cookie is your one stop for handling client side cookies. Its usage is very simple and the following example should make it clear


// To set a cookie
dojo.cookie(cookieName, cookieValue, cookieProps);
// To get a cookie
var cookieValue = dojo.cookie(cookieName);
Parameter Type Description
cookieName String Name of the cookie to set/get
cookieValue String Value of the cookie to set.
cookieProps Object Poperties of the cookie (optional, can contain any of expire (number of days, date or UTC string indicating when the cookie will expire), path, domain or secure (boolean) attributes. Use expire: -1 to delete a cookie.


Set a cookie by clicking on the button, reload the page and click the "Get Cookie" button to check whether the cookie got set.

Note: cookies must be enabled for this to work ;)

<script type="text/javascript">
dojo.require("dijit.form.Button"); // this is there only to make things look fancy
setCookie = function(){
  dojo.cookie("favouriteDish", "Nudels", {expires: 5});
getCookie = function(){
  alert("The value of the cookie is: "+dojo.cookie("favouriteDish"));
<button dojoType="dijit.form.Button" onClick="setCookie();">Set Cookie</button> <button dojoType="dijit.form.Button" onClick="getCookie();">Get Cookie</button>

See also

Mozilla documentation about cookies.

dojo/cookie (last edited 2010-02-22 15:07:40 by beusslemouton)