Introduction:
Here
I will explain how to create cookie in jQuery or read cookie
or get / set cookie in jQuery or delete cookie
in jQuery using jQuery cookie plugin. jQuery cookie plugin is
a simple, lightweight jQuery plugin for reading, writing and deleting cookies.
Description:
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
0 comments :
Post a Comment