Jquery.cookie uses documentation, $.cookie () documentation tutorials, JS operation Cookie Tutorial documentation.
Actions in Jquery.cookie:
Jquery.cookie.js is a jquery-based plugin that Https://github.com/carhartl/jquery-cookie
Create a session Cookie:
$.cookie (' cookiename ', ' cookievalue ');
Note: When no cookie time is specified, the cookie is created by default until the user's browser is closed and is referred to as a session cookie.
Create a persistent cookie:
$.cookie (' cookiename ', ' Cookievalue ', {expires:7});
Note: When a time is specified, it is called a persistent cookie and the effective time is days.
Create a persistent cookie with a valid path:
$.cookie (' cookiename ', ' Cookievalue ', {expires:7,path: '/'});
Note: If you do not set a valid path, by default, the path to the Cookie,cookie can only be read on the current page of the cookie setting to set the top-level directory that can read the cookie.
Create a persistent cookie with a valid path and domain name:
$.cookie (' cookiename ', ' Cookievalue ', {expires:7,path: '/', Domain: ' chuhoo.com ', secure:false,raw:false});
Note: domain: Domains owned by the Web page where the cookie was created; secure: false if the True,cookie transport protocol is Https;raw: false is the default. When reading and writing are automatically encoded and decoded (using encodeURIComponent encoding, using decodeuricomponent decoding), turn this feature off, set to true.
To obtain a cookie:
$.cookie (' cookiename '); Returns Cookievalue if it exists, otherwise null is returned.
To delete a cookie:
$.cookie (' cookiename ', null);
Note: If you want to delete a cookie with a valid path, as follows: $.cookie (' CookieName ', Null,{path: '/'});
Note: If you want the cookie to be shared across all two-level domains under the primary domain name, you need to set domain as '. youdomain.com ', as follows: $.cookie (' CookieName ', Null,{path: '/', Domain: '. Youdomain.com '});
The difference between the domain in the cookie: [youdomain.com] and [. youdomain.com] can be consulted:
http://stackoverflow.com/questions/2669690/why-does-google-prepend-while1-to-their-json-responses/2669766#2669766
http://stackoverflow.com/questions/1458724/how-to-set-unset-cookie-with-jquery/1458728#1458728
The code that operates the cookie, based on the $.cookie package.
Common.setcookie =function (CookieName, Cookievalue, expiresnum) {varOptions = { 'Path':'/', 'Domain': Common.globals.domain,'Secure':false,//Turn off HTTPS transport cookies 'Raw':true,//turn off the automatic encoding function of cookies 'Expires': Expiresnum | | - //expiration of a cookie if no value is passed by default for 30 days }; $.cookie (CookieName, Cookievalue, Options); } Common.getcookie=function (cookiename) {return$.cookie (cookiename); } Common.gettoken=function () {return$.cookie ('token'); } Common.delcookie=function (cookiename) {$.cookie (CookieName,"', { 'Path':'/', 'Expires': -1 }); }
Jquery.cookie uses documentation, $.cookie () documentation tutorials, JS operation Cookie Tutorial documentation.