Jquery.cookie.js How to use

Source: Internet
Author: User

Cookies

Definition: A technique that allows a Web server to store small amounts of data on the client's hard disk or memory, and to read data from the client's hard disk;

Download and introduction: Jquery.cookie.js based on jquery, first introduced jquery, then introduced: jquery.cookie.js; Download: http://plugins.jquery.com/cookie/

12 <script type="text/javascript"src="js/jquery.min.js"></script><script type="text/javascript"src="js/jquery.cookie.js"></script>

Use:

1. Add a "session cookie"

1 $.cookie(‘the_cookie‘‘the_value‘);

There is no time specified for the cookie to be valid, and the cookie is created by default until the user closes the browser, so it is referred to as a "session cookie".

2. Create a cookie and set the validity time to 7 days

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

This indicates the time the cookie is valid and the cookie created is referred to as a "persistent cookie (persistent cookie)". Note units are: days;

3. Create a cookie and set a valid path for the cookie

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

By default, only the Web page that sets the cookie can read the cookie. If you want a page to read a cookie set by another page, you must set the path to the cookie. The path to the cookie is used to set the top-level directory to read cookies. Set this path to the root of your Web site so that all Web pages can read cookies to each other (typically not set up to prevent collisions).

4. Read cookies

1 $.cookie(‘the_cookie‘);

5. Delete Cookies

1 $.cookie(‘the_cookie‘null);   //通过传递null作为cookie的值即可

6. Optional Parameters

123456 $.cookie ( ' The_cookie ' The_value ' ,{       EXPIRES:7,&NBSP;&NBSP;      path: '/' &NBSP;&NBSP;&NBSP;&NBSP; Code class= "JavaScript plain" >domain: ' jquery.com ' &NBSP;&NBSP;&NBSP;&NBSP; secure: true })

expires: (number| date); When an integer is set, the unit is days; You can also set a Date object as the expiration date of the cookie;
path: (String) creates the page path for the cookie;
domain: (String) The domain name of the page that created the cookie;
Secure: (Booblean) If set to true, then the transfer of this cookie will require a security protocol such as: HTTPS;

Jquery.cookie.js How to use

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.