-
Notifications
You must be signed in to change notification settings - Fork 0
TOOL easyCookies
Gix075 edited this page Feb 4, 2016
·
4 revisions
easyCookies is a simple way to handle browser cookies.
This tool is included on jqueryEasyTools but you can use it also in "stand alone" mode, installing only its javascript.
<script src="jquery.min.js"></script>
<script src="js/easyCookies.min.js"></script>
Initialize easyCookies
var cookies = new easyCookies();
// write cookie
// =================================
var writeOpts = {
name: "CookieName",
value: "CookieValue",
expires: 30,
callback: function(result) {
[...]
}
}
cookies.writeCookie(writeOpts);
If you want write a session cookie, simply set the "expires" parameter to 0 ( expires: 0 )
// read cookie
// =================================
cookies.readCookie("cookieName");
// delete cookie
// =================================
cookies.deleteCookie("cookieName");
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);