Jquery.cookie usage Analysis

Source: Internet
Author: User
Tags set cookie valid

  This article is mainly on the use of Jquery.cookie detailed analysis of the introduction, the need for friends can come to the reference, I hope to help you.

A lightweight cookie plugin that can read, write, and delete cookies.   Jquery.cookie.js configuration     First contains jquery's library files, followed by Jquery.cookie.js's library file   <script type= "text/ JavaScript "src=" Js/jquery-1.6.2.min.js "></script>  <script type=" Text/javascript "src=" js/ Jquery.cookie.js "></script>     use method   New Add a session cookie:     $.cookie (' The_cookie ', ' the _value ');    NOTE: When a cookie is not valid, the creation of the cookie is not valid until the user closes the browser, so it is called "Session cookie"     Create a cookie and set a valid time of 7 days:     $.cookie (' The_cookie ', ' The_value ', {expires:7});    Note: When the cookie valid time is specified, The cookie you create is called a persistent cookie (persistent cookie).     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 a cookie for another page setting, you must set the path of the cookie. The path to the   cookie is used to set up a top-level directory that can read cookies. Set this path to the root of the Web site so that all pages can read cookies to each other (generally do not set up to prevent conflicts)     Read cookies:   $.cookie (' The_cookie ');   //Cookies exist => ' the_value ' $.cookie (' not_existing '); The cookie does not exist => null     Delete cookies, passing null as the value of the cookie:   $.cookie (' The_cookie ', null);     explanation of related parameters   expires:365   Defines the valid time for a cookie, which can be one (from the time the cookie was created, in days), or a date.   If omitted, the cookie created is a session cookie that will be deleted when the user exits the browser.     Path: '/'   default: Only a Web page that sets a cookie can read the cookie.     Define a valid path for the cookie. By default, the value of this parameter is the path of the Web page where the cookie was created (the behavior of the standard browser).   If you want to access this cookie throughout the site, you need to set a valid path: path: '/'.   If you want to delete a cookie that defines a valid path, you need to include this path when calling the function: $.cookie (' The_cookie ', NULL, {path: '/'});.     domain: ' example.com '   default: Create a cookie on the Web page owned by the domain name.     secure:true   default value: False. If the transport for True,cookie requires the use of security Protocol (HTTPS).     raw:true   default value: False. By default, encoding and decoding is done automatically when the cookie is read and written (using encodeURIComponent encoding, decodeuricomponent decoding).   To turn off this feature setting raw:true.       $.cookie (' The_cookie '); Get Cookie $.cookie (' The_cookie ', ' the_value '); Set Cookie $.cookie (' The_cookie ', ' thE_value ', {expires:7}); Set cookie with a expiration date seven in the Future $.cookie (' The_cookie ', ', {Expires:-1}); Delete cookie  $.cookie (' The_cookie ', null); Delete Cookie     $.cookie (' The_cookie ', ' The_value ', {expires:7, path: '/', Domain: ' 80tvb.com ', secure:true //Full invocation mode    /or this: $.cookie (' The_cookie ', ' the_value ');  //Delete cookies: $.cookie (' The_cookie ', null);       jquery operation Cookie Plug-ins, the approximate use of the following   $.cookie (' The_cookie '); Read Cookie value $.cookie (' The_cookie ', ' the_value '); Set the value of the cookie $.cookie (' The_cookie ', ' The_value ', {expires:7, path: '/', Domain: ' jquery.com ', secure:true}); Create a new cookie including the expiration path domain name $.cookie (' The_cookie ', ' the_value '); New Cookie $.cookie (' The_cookie ', null); Delete a cookie     set cookie expiration time and check whether cookies are available   Let cookies expire in x minutes var date = new Date (); Date.settime (Date.gettime () + (x * 60 * 1000)); $.cookie (' Example ', ' foo ', {expires:date});   $.cookie (' Example ', ' foo', {expires:7});     Check whether cookies are available $ (document). Ready (function () {var dt = new Date ();d t.setseconds (dt.getseconds () + 60); Document.cookie = "cookietest=1; Expires= "+ dt.togmtstring (); var cookiesenabled = Document.cookie.indexof (" cookietest= ")!= -1;if (!cookiesenabled) {// Cookies cannot be used ...});      

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.