About jquery Cookies plugin 2.2.0 version set expiration time description

Source: Internet
Author: User

jquery should be a common tool for web development with JavaScript, and some plugins can easily manipulate cookies.

The first thing to note is that there are two main domestic popular cookies, one is early in 2006 do not know what version number called the plug-in, and the other is the 2.2.0 version of the cookie, note that the latter name than the former one s, the main domestic use is the latter. The former has already stopped maintenance (or the Code rarely needs maintenance) and its download links have been removed from the website, and the download links are everywhere. You are the latter, the official download in: http://code.google.com/p/cookies/downloads/list

How to use the cookie plugin:

1. Needless to say, first you have to download the jquery and cookies plugin.

2. On the <body> front of the website, add:

<type= "Text/javascript"  src= "/jquery-1.2.6.min.js"> </script><type= "Text/javascript" src = "/jquery.cookies.2.2.0.min.js" ></ Script >

The long string behind src= is the file name of the jquery and cookie plugin you downloaded, and if you're not the same as me, change it.

3. How to add/modify cookies and set expiration time:

$.cookies.set (' cookie_id ', ' Cookie_value ', {hourstolive:100});

Above is to add or modify a cookie and set its expiration/expiration time after 100 hours, note that curly braces are required.

Expiration expiry time there is another way to specify an absolute time:

New+ (+ * + ); $.cookies.set (' cookie_id ', ' Cookie_value ')
// the Expireat parameter is accurate to milliseconds. You can also add path, domain, secure and other parameters in the curly braces, which are not introduced here. If both hourstolive and Expiresat are specified, the Expiresat will prevail. 

4. How to obtain cookies

5. How to delete cookies

6. Working with JSON

var msg={username: "Demo1", Password: "Demo2"};$.cookies.set ("Cookie_d", msg); // Save Data var d = $.cookies.get ("Cookie_d"); // Fetch Data var u = $.cookies.get ("Cookie_d"). Username; var p = $.cookies.get ("cookie_d"). Password;

It's so much more common. Cookies have more advanced usage, such as the ability to write an array of one breath into a cookie, but not in the scope of this article.

About jquery Cookies plugin 2.2.0 version set expiration time description

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.