A tiny JavaScript script for managing browser Cookies.
Download the source file and include in your HTML file(s):
Cookie.set(strName, strVal, fDays=1, strPath='/', bSec=false);
-
strName
Name of the cookie to be set -
strValue
Value of the cookie to be set -
fDays
The number of days before expiring the cookie. From now.
Default: 1 day -
strPath
The path from where the cookie is valid, starting from the root.
Default: root / -
bSec
Is the cookie only available through a secure connection (https)?
Default: false
Create a cookie, expiring in 1 day and valid across the site:
Cookie.set('cookiename', 'cookievalue');
Create a cookie that expires 5 days from now and valid across the site:
Cookie.set('cookiename', 'cookievalue', 5);
Create a cookie that expires in 5 days and is valid from your /js folder and subfolder:
Cookie.set('cookiename', 'cookievalue', 5, '/js');
Read a cookie:
Cookie.get('cookiename') // => cookie's value
Cookie.get('wrongname') // => undefined
Delete a cookie:
Cookie.del('cookiename')
Note: Removing a nonexistent cookie neither raises any exception nor returns any value.
Check out the Contributing Guidelines
For vulnerability reports, send an e-mail to js-cookie at derekerb dot solutions