A ridiculously small (~500 bytes minified) jQuery plugin for writing, reading and deleting cookies
Zebra_Cookie has no dependencies other than jQuery 1.0+
Zebra_Cookie is available as a npm package. To install it use:
npm install zebra_cookie
Zebra_Cookie is also available as a Bower package. To install it use:
bower install zebra_cookie
First, load jQuery from a CDN and provide a fallback to a local source like:
Load the Zebra_Cookie jQuery plugin:
Alternatively, you can load Zebra_Cookie from JSDelivr CDN like this:
<!-- for the most recent version --><!-- for a specific version --><!-- replacing "min" with "src" will serve you the non-compressed version -->
// inside the DOM-ready function// a "cookie" object will be available in jQuery’s namespace// the object exposes 3 methods that you can use to write, read and delete cookies;
Removes a cookie from the browser.
TRUE on success or
name - the name of the cookie to remove
// create a session cookie (expires when the browser closes)$cookie;// delete the cookie$cookie;
Reads the value of a cookie.
Returns the value of the requested cookie or
null if the cookie doesn't exist.
name - the name of the cookie to read
// create a session cookie (expires when the browser closes)$cookie;// read a cookie's value// following the examples above, this should return "cookie_value"$cookie;
Sets a cookie in the browser.
TRUE if the cookie was successfully set, or
name - The name of the cookie to set
value - The value to set
expire - (optional) - The life time of the cookie, in seconds. If set to
0, or omitted, the cookie will expire at the end of the session (when the browser closes).
path - (optional) - The path on the server in which the cookie will be available on. If set to
/, the cookie will be available within the entire domain. If set to
/foo/, the cookie will only be available within the
/foo/ directory and all subdirectories such as
/foo/bar/ of the domain. If omitted, it will be set to
domain - (optional) - The domain that the cookie will be available on. To make the cookie available on all sub-domains of
example.com, domain should be set to to
. (dot) is not required but makes it compatible with more browsers. Setting it to
www.example.com will make the cookie available only in the
secure - (optional) - Indicates whether cookie information should only be transmitted over a HTTPS connection. Default is
// create a session cookie (expires when the browser closes)$cookie;// create a cookie that expires in 1 day$cookie;
See the demos