Skip to content
Gix075 edited this page Feb 4, 2016 · 4 revisions

easyCookies is a simple way to handle browser cookies.

USAGE

This tool is included on jqueryEasyTools but you can use it also in "stand alone" mode, installing only its javascript.

Installation

<script src="jquery.min.js"></script>
<script src="js/easyCookies.min.js"></script>

USAGE

Initialize easyCookies

    var cookies = new easyCookies();

Methods

.writeCookie()

    // write cookie
    // =================================
    var writeOpts = {
        name: "CookieName",
        value: "CookieValue",
        expires: 30,
        callback: function(result) {
            [...]
        }
    }
    cookies.writeCookie(writeOpts);
Session Cookie

If you want write a session cookie, simply set the "expires" parameter to 0 ( expires: 0 )

.readCookie()

    // read cookie
    // =================================
    cookies.readCookie("cookieName");

.deleteCookie()

    // delete cookie
    // =================================
    cookies.deleteCookie("cookieName");

.matchCookieValue()

This method can match the cookie value with another value passed to the function as "value".
This method return a callback function with bool result (true/false) passed as argument.

    // match cookie value
    // =================================
    var matchOpts = {
        name: "CookieName",
        value: "Cookie Value", 
        callback: function(result) {
            [...]
        }
    }
    cookies.matchCookieValue(matchOpts);