Skip to content

An incredibly simple and lightweight library for adding, fetching, modifying, and removing browser cookies.

Notifications You must be signed in to change notification settings

Gigabyte5671/CookieManager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CookieManager.js

JavaScript Cookie Manager

Demo

An incredibly simple and lightweight library for creating, reading, updating, and deleting browser cookies.

Usage

Include:

<script src="https://gigabyte5671.github.io/CookieManager/cookieManager.min.js" type="text/javascript"></script>

Or download the zip from the releases page.

To create a cookie, call the setCookie() function with arguments for the cookie name, the value, and the lifespan (in days).
(To update a cookie, just call setCookie() again with the same name and the new value)

setCookie(cookieName, cookieValue, cookieLifespan);

To retrieve the value of a cookie, call the getCookie() function with an argument for the cookie name. This will return the value of the cookie as a string.

var cookieValue = getCookie(cookieName);

To check if a cookie exists, call the checkCookie() function with an argument for the cookie name. This will return boolean true if the cookie exists, and boolean false if it doesn't.
(This function is faster than getCookie if you don't need to know the cookie's value)

var cookieExists = checkCookie(cookieName);

Finally, to remove a cookie, call the clearCookie() function with an argument for the cookie name.

clearCookie(cookieName);

Note: Most browsers enforce a maximum size of 4096 bytes per cookie. Attempting to set or update a cookie with a value larger than that will fail without returning an error.

Other

Cookies icon by Icons8

About

An incredibly simple and lightweight library for adding, fetching, modifying, and removing browser cookies.

Topics

Resources

Stars

Watchers

Forks