Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

jQuery Cookie Create, Get (Read), Delete (Erase) with Example

Sep 24, 2015
Introduction

Here I will explain how to create cookie in jQuery or read cookie or get / set cookie in jQuery or set cookie expire or delete cookie in jQuery using jQuery cookie plugin. jQuery cookie plugin is a simple, lightweight plugin to create, read / get, set expire for cookies using $.cookie() function.

Description:

In previous articles I explained Best jQuery Audio Player Plugin Examples, Top video player plugin examples, 8 Best jQuery popup window plugins, 8 jQuery page flip book effect plugins, jQuery Draggable & Resizable div with example and many articles relating to jQuery, JavaScript, jQuery Plugins. Now I will explain how to create, get/set, delete cookie in jQuery using jQuery cookie plugin.

First download jQuery cookie plugin from this site jQuery cookie and add it to your application then try follow below methods to create, get, delete cookies

Create Cookie


$.cookie('the_cookie', 'the_value');

Create expiring cookie 7 days from then:


$.cookie('the_cookie', 'the_value', { expires: 7 });

Create expiring cookie, valid across entire site:


$.cookie('the_cookie', 'the_value', { expires: 7, path: '/' });

Read Cookie


$.cookie('the_cookie'); // => "the_value"
$.cookie('not_existing'); // => undefined


Read all available cookies
:


$.cookie(); // => { "the_cookie": "the_value", "...remaining": "cookies" }

Delete Cookie:


// Returns true when cookie was found, false when no cookie was found...
$.removeCookie('the_cookie');

// Same path as when the cookie was written...
$.removeCookie('the_cookie', { path: '/' });

Available Cookie Options

Expires

Define lifetime of the cookie. Value can be a Number which will be interpreted as days from time of creation or a Date object. If omitted, the cookie becomes a session cookie.

Path

Define the path where the cookie is valid. By default the path of the cookie is the path of the page where the cookie was created (standard browser behavior). If you want to make it available for instance across the entire domain use path: '/'. Default: path of page where the cookie was created.

Domain

Domain of page where the cookie was created.

Secure

If true, the cookie transmission requires a secure protocol (https). Default: false.

For more details of using cookie plugin check this url jquery cookie

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

2 comments :

kafa topu said...

Thanks..

Unknown said...
This comment has been removed by the author.

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.