Javascript: cookie function code _ javascript skills

Source: Internet
Author: User
Javascript to read the cookie Function Code. For more information, see. Usage:
1. Set cookie

The Code is as follows:


Var cookie = new JSCookie ();
// Normal settings
Cookie. SetCookie ("key1", "val1 ");
// The expiration time is one year.
Var expire_time = new Date ();
Expire_time.setFullYear (expire_time.getFullYear () + 1 );
Cookie. SetCookie ("key2", "val2", expire_time );
// Set the domain and path with the expiration time
Cookie. SetCookie ("key3", "val3", expire_time, ".cnblogs.com ","/");
// Set the cookie of the BIND key. The subkeys are k1, k2, and k3.
Cookie. SetCookie ("key4", "k1 = 1 & k2 = 2 & k3 = 3 ");



Ii. Reading cookies

The Code is as follows:


// Simple retrieval
Cookie. GetCookie ("key1 ");
Cookie. GetCookie ("key2 ");
Cookie. GetCookie ("key3 ");
Cookie. GetCookie ("key4 ");
// Obtain the key 1 Value of key4
Cookie. GetChild ("key4", "k1 ");



Iii. Delete

The Code is as follows:


Cookie. Expire ("key1 ");
Cookie. Expire ("key2 ");
Cookie. Expire ("key3 ");
Cookie. Expire ("key4 ");



Example:

The Code is as follows:


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.