Read – write cookie – javascript – Jquery
An easy to use Jquery plug-in for reading and writing cookies. There are traditional ways to read and write cookies using plane javascript(http://www.quirksmode.org/js/cookies.html) but if you are using Jquery in your solution, you can minimize your effort by using this plug-in. You will require Jquery core (jquery.js) for using this plug-in. below are some examples of usage for this jquery.cookie plug-in:
1. How to write a cookie:
$.cookie('the_cookie_name', 'the_value');
2. How to read a cookie:
$.cookie('the_cookie_name');
3. How to delete a cookie:
$.cookie('the_cookie_name', null);
4. How to write a cookie with optional parameters:
$.cookie('the_cookie_name', 'the_value', {expires: 7, path: '/', domain: 'jquery.com', secure: true});
Optional parameters:
a. expires: Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
*If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
*If set to null or omitted, the cookie will be a session cookie and will not be retained when the the browser exits.
b. path: String path The value of the path atribute of the cookie (default: path of page that created the cookie).
c. domain: String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
d. secure: Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will require a secure protocol (like HTTPS).
Most Commented Posts
If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments
No comments yet.
Leave a comment