-
Notifications
You must be signed in to change notification settings - Fork 0
NuiCookie
maxcal edited this page May 30, 2011
·
6 revisions
##Abstract nui.cookie is a helper method to set and read cookies. It is designed to give simple and predictable return values. It can be mixed into nui plugins or used straight up on a page.
It uses CRUD (create, read, update, destroy) conventions.
##Public methods
-
nui.cookie.create('name', 'value', days, 'path')
- returns the newly created cookie -
nui.cookie.read('name')
- returns the value of the cookie if the cookie exist - otherwise returns null. -
nui.cookie.update('name', 'value', days, 'path')
- checks if cookie exists - if it does it updates the cookie value. -
nui.cookie.destroy('name','path')
- Expires the cookie (browser will delete cookie).
##Examles
// Javascript:
// create a cookie
nui.cookie.create('name', 'value', days, 'path');
nui.cookie.create('foo', 'bar', 14, 'finland');
will create a cookie named foo, with a value of bar readable from greenpeace.org/finland/ for 14 days.
// Read a cookie
nui.cookie.read('foo');
// returns 'bar'
nui.cookie.read('doesnotexist');
// returns null.
// to check for a cookie:
if (nui.cookie.read('foo')){
// User has cookie named foo. Bail!
}