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