Cookie plugin for JavaScript operations

Source: Internet
Author: User

The javascript operation cookie plug-in has been clearly marked. Please refer to the detailsCode:

 

// Cookie class <br/> function cookie () {<br/> cookie. prototype = new object (); // inherits from object <br/> This. constructor = cookie; <br/> // rewrite the tostring function to generate a document. cookie string <br/> cookie. prototype. tostring = function () {<br/> var DATA = []; // store the cookie subkey <br/> VaR _ cookie = []; // store Cookie key-value pairs <br/> for (VAR prop in this) {<br/> switch (true) {<br/> case prop = "name ": <br/> _ cookie [0] = prop; <br/> continue; <br/> case prop = "expires ": <br/> _ cookie [1] = prop + "=" + this [prop]; <br/> continue; <br/> case prop = "path ": <br/> _ cookie [2] = prop + "=" + this [prop]; <br/> continue; <br/> case prop = "secure ": <br/> _ cookie [3] = prop + "=" + this [prop]; <br/> continue; <br/> case prop = "Domain ": <br/> _ cookie [4] = prop + "=" + this [prop]; <br/> continue; <br/>}< br/> data [data. length] = prop + ":" + escape (this [prop]); <br/>}< br/> _ cookie [0] + = "=" + data. join ("&"); <br/> return _ cookie. join (";"); <br/>}; <br/> return this; // return the cookie object <br/>}< br/> // format the string as a cookie, static function <br/> cookie. format = function (STR) {<br/> var cookie = new cookie (); <br/> var start = Str. indexof ("="); <br/> cookie. name = Str. substring (0, start); <br/> VaR value = Str. substring (start + 1); <br/> value = value. split ('&'); <br/> for (var v in value) {<br/> V = v. split (':'); <br/> This [V [0] = Unescape (V [1]); <br/>}< br/> return cookie; <br/>}; <br/> // obtain all current cookies and static objects <br/> cookies. cookies = (function () {<br/> var cookie = document. cookie; <br/> var OBJ; <br/> cookie = cookie. split (';'); <br/> for (var c in cookie) {<br/> C = cookie. format (c); <br/> OBJ [C. name] = C; <br/>}< br/> return OBJ; <br/>}) (); <br/> // Add a cookie, static functions <br/> cookie. add = function (cookie) {<br/> If (cookie instanceof cookie) {<br/> document. cookie = cookie. tostring (); <br/>}< br/> // else console. log ("parameter error"); <br/>}< br/> // Delete cookie, static function <br/> cookie. remove = function (cookie) {<br/> If (cookie instanceof cookie) {<br/> var time = new data (); <br/> time. setfullyear (time. getfullyear ()-10); <br/> cookie. expires = time. togmtstring (); <br/> document. cookie = cookie. tostring (); <br/>}< br/>

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.