jCookie – jQuery Plugin

Description

jCookie is a basic jQuery Cookie plugin. It is an easier front end for creating, modifying and deleting cookies.

Information

Reporting Bugs

If you find any bugs please don’t comment on this page. Report any bugs through Github.

Versions

Current Version – 1.1.1

Links:

Download via Github Page

Usage

Options

expires - Default: ''
          (Must be a valid date string or a number, e.g 1 for 1 day,
           If empty default to browser session, e.g gets destroyed when browser closes)
domain - Default: ''
         e.g jquery.com
path - Default: ''
       (Path of website cookie is valid on, e.g /products/ for example.com/products/
        Can be '' to default to page cookie was created on)
secure - Default: false
         (Whether you cookie is on a secure)

Basic Example


    $.cookie("cookie_name", "cookie_value",{
        path : "/", //Whole website
        domain : "example.com",
        expires : 2 //2 Days time
    });

Advanced Example


    //Set global settings for all cookies
    $.cookie.settings = {
        path : "/",
        domain : "example.com",
        expires : 2
    };

    $.cookie("cookie_name", "cookie_value");
    $.cookie("cookie_name2", "cookie_value2");

Deleting a Cookie

//Passing null to the cookie plugin will delete it
$.cookie('cookie_name', null);

Checking if Cookies are enabled

if( $.support.cookies ) {
    //Supported
}