Cookie operations in JavaScript _ javascript skills

Source: Internet
Author: User
This article mainly introduces the Cookie operation examples in JavaScript. This article first explains the Cookie syntax and then provides the actual operation examples. For more information, see JavaScript Cookie

Cookie object:
Cookie is the user data (Cookie data) stored in the Cookies folder on the client's hard disk in the form of files ).
The Cookie file is created by the Accessed Web Site to Store session data between the client and the Web site for a long time. the Cookie data can only be read by the Accessed Web site.
Cookie file format:
NS: Cookie.txt
IE: user name @ domain name .txt


There are two types of cookies:
(1) persistent cookies are stored on the client's hard disk.
(2) session Cookie: it is stored in the memory of the browser process instead of the client's hard disk. when the browser is closed, the session cookie is destroyed.

Use JS to implement Cookie operations

Write Cookie:

The code is as follows:


Document. cookie = "keyword = value [; expires = Valid date] [;...]"


Read Cookie:

The code is as follows:


Document. cookie


Delete Cookie:

The code is as follows:


Document. cookie = "keyword =; expires = current date"


Note:

1. Valid date format: Wdy, DD-Mon-yy hh: MM: SS GMT
2. Wdy/Mon: English week/month;
3. it also contains the path, domain, and secure attributes;
4. each Web site (domain) can establish 20 Cookie data;
5. each browser can store 300 Cookie data, 4 K bytes;
6. the customer has the right to prohibit writing Cookie data.

Instance

The code is as follows:





CookieTest.html








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.