Jquery. cookie. js usage, jquery. cookie. js
Download and introduction: jquery. cookie. js Based on jquery; first introduce jquery, and then introduce: jquery. cookie. js; download https://files.cnblogs.com/files/chuanyueinlife/jquery.cookie.js
1 <script type="text/javascript" src="js/jquery.min.js"></script>2 <script type="text/javascript" src="js/jquery.cookie.js"></script>
Usage:
1. Add a "session cookie"
$.cookie('the_cookie', 'the_value');
The cookie validity period is not specified here. The created cookie is valid until the user closes the browser by default. Therefore, it is called "session cookie )".
2. Create a cookie and set the validity period to 7 days.
$.cookie('the_cookie', 'the_value', { expires: 7 });
The cookie validity period is specified here. The cookie created is called "persistent cookie )". Note that the unit is: Day;
3. Create a cookie and set the valid cookie Path.
$.cookie('the_cookie', 'the_value', { expires: 7, path: '/' });
By default, only webpages with cookie settings can read the cookie. If you want a page to read the cookie set for another page, you must set the cookie Path. The cookie Path is used to set the top-level directory that can read cookies. Set this path as the root directory of the website so that all webpages can read cookies from each other (do not set it like this to prevent conflicts ).
4. Read cookie
$.cookie('the_cookie');
5. Delete cookies
$. Cookie (the _ cookie, null); // pass null as the cookie value.
6. Optional parameters
$.cookie('the_cookie','the_value',{ expires:7, path:'/', domain:'jquery.com', secure:true})
Expires(Number | Date) validity period. If you set an integer, the unit is day. You can also set a Date object as the Cookie's expiration Date;
Path(String) the page path for creating the Cookie;
Domain:( String) the Domain Name of the page where the Cookie is created;
Secure(Booblean) if it is set to true, the transmission of this Cookie requires a security protocol, for example: HTTPS;