Jquery. cookie. js usage, jquery. cookie. js

Source: Internet
Author: User

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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.