Using cookies in JavaScript

Cookies are small items of data, each consisting of a name and value,
stored on behalf of a website by visitors’ web browsers. In JavaScript, cookies can be accessed through the document.Cookies.js is a JavaScript object that allows cookies to be created, retrieved, and deleted through a simple and intuitive interface.
Download the Cookies.js files below and use them for cookies.

how to SetCookie:

Cookie.Set(\'color\',\'blue\');

For creating cookies set 2 parameters cookie name and parameter.
The value of the property can be either a date on which the cookie will expire or a number of seconds after which the cookie should expire:

Cookies.set(\'theme\', \'green\', {expiry : 3600});

if you want cookies to access only one domain then
Cookies.set(‘name’, ‘Shilpa’, {expiry : new Date(2030, 0, 1)});

Retrieving Cookies

if you retrieve, the cookie’s value then,

var theme = Cookies.get(\'color\');

Deleting cookies

if you delete the value of the cookie then,

Cookies.clear(\'color\');

For details please see http://code.iamkate.com/javascript/using-cookies/

2 thoughts on “Using cookies in JavaScript”

Comments are closed.