Skip to content

DerekErb/js-cookie

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JavaScript Cookie

A tiny JavaScript script for managing browser Cookies.

Installation

Direct download

Download the source file and include in your HTML file(s):

Basic Usage

  Cookie.set(strName, strVal, fDays=1, strPath='/', bSec=false);

Parameters

  • 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 Cookies

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 Cookies

Read a cookie:

  Cookie.get('cookiename')  // => cookie's value
  Cookie.get('wrongname')   // => undefined

Deleting Cookies

Delete a cookie:

  Cookie.del('cookiename')

Note: Removing a nonexistent cookie neither raises any exception nor returns any value.

Contributing

Check out the Contributing Guidelines

Security

For vulnerability reports, send an e-mail to js-cookie at derekerb dot solutions

Authors