JavaScript Action Cookie Simple plugin

Source: Internet
Author: User
Tags setcookie

JavaScript Action Cookie Simple plugin:
The appropriate and flexible use of cookies can bring a lot of convenience to users, although it has been criticized by many people, but its application is everywhere, about the cookie is not introduced here, specifically, you can refer to JavaScript how to operate the cookie section, Here is a simple plugin for manipulating cookies, with the following code:

varCookie={  //Create a cookieSetcookie:function(name, value, Iday) {varOdate =NewDate (); Odate.setdate (Odate.getdate ()+iday); Document.cookie= name+ ' = ' +value+ '; expires= ' +odate; },   //Read CookiesGetCookie:function(name) {vararr = Document.cookie.split ('; ‘);  for(vari = arr.length-1; I >= 0; i--) {       varARR2 = arr[i].split (' = ')); if(arr2[0]===name) {         returnArr2[1]; }     }     return‘‘; },   //Delete CookiesRemovecookie:function(name) {Cookie.setcookie (name,1,-1); } };

This plugin provides three features for creating cookies, reading cookies, and deleting cookies, and the code demonstrates:

Cookie.setcookie (' username ', ' Ant Tribe '),Cookie.removecookie (' username ');

The above code first creates a cookie with the name "username", the value "Ant Tribe", expires after 30 days, and the second paragraph is to delete this cookie.

The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=7980

For more information, refer to: http://www.softwhy.com/javascript/

JavaScript Action Cookie Simple plugin

Related Article

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.