Cookie object_basic knowledge-js tutorial

Source: Internet
Author: User
This article briefly introduces the concept of cookie objects in javascript, as well as the methods for reading, writing, and deleting cookies, and attaches an example, which is very good. We recommend it to our friends here. 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:

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

Read Cookie:

Document. cookie

Delete Cookie:

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






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.