jquery Plugin--Cookie plugin Jquery.cookie.js

Source: Internet
Author: User

A cookie is a small text file that the Web designer places on the client. Cookies can provide users with a number of things, such as a list of products that a shopping site stores users have visited, or a portal that remembers what kind of news users prefer to browse. Users can also store logon information for users, allowing them to access the site without having to type it each time

Cookie:http://plugins.jquery.com/project/cookie

How to use:

1. Introduction of Jquery.cookie.js

<script src= "Scripts/jquery-1.6.4.js" type= "Text/javascript" ></script>  <script src= "scripts/ Jquery.cookie.js "type=" Text/javascript "></script>  

2. How to use

1). Add a new session cookie:

$.cookie (' The_cookie ', ' the_value ');

Note: When the cookie is not valid, the cookie is created by default until the user closes the browser, so it is called

"Session Cookie".

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

$.cookie (' The_cookie ', ' The_value ', {expires:7});

Note: When a cookie is specified, the cookie created is referred to as a "persistent cookie (persistent cookie)".

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

$.cookie (' The_cookie ', ' The_value ', {expires:7, path: '/'});

Note: By default, only the Web page that sets the cookie can read the cookie. If you want a page to read another page set

Cookies, you must set the path of the cookie. The path to the cookie is used to set the top-level directory to read cookies. Put this

The path is set to the root of the Web site, allowing all pages to read cookies to each other (typically not set to prevent conflicts).

4). Read the Cookie:

$.cookie (' The_cookie '); Cookie exists = ' The_value '

$.cookie (' not_existing '); Cookie does not exist = NULL

5). Delete the cookie by passing null as the value of the cookie:

$.cookie (' The_cookie ', null);

3. Writing a cookie to a file

varCookie_name = ' username '; if($.cookie (Cookie_name)) {$ ("#username"). Val ($.cookie (Cookie_name)); }      $("#check"). Click (function(){          if( This. Checked) {$.cookie (Cookie_name, $ ("#username"). Val (), {path: '/', expires:10, domain: ' jquery.com ', secure:true }); //var date = new Date ();             //Date.settime (Date.gettime () + (3 * 24 * 60 * 60 * 1000));//After three days, this time expires            //$.cookie (Cookie_name, $ ("#username"). Val (), {path: '/', expires:date}); }Else{$.cookie (cookie_name,NULL, {path: '/'});//Delete Cookies        }      });

Parameter settings: Expires: (number | Date), you can set an integer as the validity period (in days), or you can set a Date object as the expiration date for the cookie. If the specified date is negative, the cookie will be deleted, and if not set or set to NULL, then this cookie will be treated as a session cookie and deleted after the browser is closed

Path: (String) A cookie that is by default the page path that created the cookie

Domain: (String) The name attribute of the cookie, which is the page domain name that created the cookie by default

Secure: (Boolean) If set to true, then the transfer of this cookie requires a security protocol such as HTTPS

jquery Plugin--Cookie plugin jquery.cookie.js (RPM)

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.