Jquery.cookie plugin Usage Self-summary

Source: Internet
Author: User
Tags set cookie

Jquery.cookie-----A plug-in that encapsulates a cookie. (Based on jquery)

I just need to call it.

$.cookie ("C_name", c_value,{expires:7});

You can use alert ($.cookie ("C_name")) to get the content you want to store so that the test cookie is stored;

C_name: The name of the cookie to be created;

C_value: The value or content to be stored;

Expires:7 storage date;

$.cookie ("C_name", null), or//Turn off the cookie, which can be known by the alert ($.cookie ("C_name")) to Null to know that the cookie has been cleared.

In addition, automatically stored every 5 minutes, that is, set the timer

SetInterval (function () {

$.cookie ("C_name", c_value,{expires:7});

},300000)

$ (#input). Val ($.cookie ("C_name"));//Read the cookie and the cookie is re-assigned to the original object when the page refreshes

Record it again.

JS gets the elements in the IFRAME (this is in case the IFRAME has no ID or name, etc.):

var iframe = document.getelementsbytagname (' iframe ') [0];

var ifr_document = iframe.contentWindow.document;

$ (ifr_document). Find (' #editor ');//Get the element with ID editor in the IFRAME;

Jquery.cookie Plugin source code is as follows:

Jquery.cookie = function (name, value, options) {
if (typeof value! = ' undefined ') {//name and value given, set cookie
options = Options | | {};
if (value = = = null) {
Value = ';
Options.expires =-1;
}
var expires = ';
if (Options.expires && (typeof options.expires = = ' Number ' | | options.expires.toUTCString)) {
var date;
if (typeof options.expires = = ' number ') {
Date = new Date ();
Date.settime (Date.gettime () + (Options.expires * 24 * 60 * 60 * 1000));
} else {
date = Options.expires;
}
expires = '; Expires= ' + date.toutcstring ();
}
var path = Options.path? ‘; Path= ' + (Options.path): ';
var domain = Options.domain? ‘; Domain= ' + (options.domain): ';
var secure = options.secure? ‘; Secure ': ';
Document.cookie = [name, ' = ', encodeURIComponent (value), expires, path, domain, Secure].join (");
} else {
var cookievalue = null;
if (document.cookie && document.cookie! = ") {
var cookies = Document.cookie.split (';');
for (var i = 0; i < cookies.length; i++) {
var cookie = Jquery.trim (Cookies[i]);
if (cookie.substring (0, name.length + 1) = = (name + ' = ')) {
Cookievalue = decodeURIComponent (cookie.substring (name.length + 1));
Break
}
}
}
return cookievalue;
}
};

Jquery.cookie plugin Usage Self-summary

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.