Super Tiny Cookie Handling Plugin with jQuery - Zebra_Cookie

File Size: 69.9 KB
Views Total: 580
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   
Super Tiny Cookie Handling Plugin with jQuery - Zebra_Cookie

Zebra_Cookie is a super tiny plugin that allows you easily and quickly to set, write, read and remove cookies in jQuery.

You might also like:

How to use it:

1. Include the latest jquery library on your page

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

2. Include zebra_cookie.js after jquery

<script type="text/javascript" src="zebra_cookie.js"></script>

3. Usage

// 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
$(document).ready(function() {
 
    // create a session cookie (expires when the browser closes)
    $.cookie.write('cookie_name', 'cookie_value');
 
    // create a cookie that expires in 1 day
    $.cookie.write('cookie_name', 'cookie_value', 24 * 60 * 60);
 
    // read a cookie’s value
    // following the examples above, this should return "cookie_value"
    $.cookie.read('cookie_name');
 
    // the "read" method returns null if the cookie doesn’t exist
    $.cookie.read('non_existing_cookie_name');
 
    // delete the cookie
    $.cookie.destroy('cookie_name');
 
});

This awesome jQuery plugin is developed by unknown. For more Advanced Usages, please check the demo page or visit the official website.