This article briefly introduces the methods and examples for using javascript to operate cookie objects. For more information, see
Cookie object
It is a data information (Cookie data) stored in the Cookies folder on the client's hard disk in the form of a file (Cookie file ). User Data (Cookie data) in the Cookie folder ). 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. (Cross-origin access is not allowed)
Cookie file format:
NS: Cookie.txt
IE: User Name @ domain name .txt
Javascript write Cookie
Format:
Document. cookie = "keyword = value [; expires = valid date] [;…]"
Note:
Valid Date Format: Wdy, DD-Mon-yy hh: MM: SS
Wdy/Mon: English week/month;
It also contains path, domain, and secure attributes;
20 Cookie data can be created for each Web site (domain;
Each browser can store 300 Cookie data, 4 K bytes;
The customer has disabled writing Cookie data.
Using js to operate on cookies is much more troublesome than using jsp servlet to operate on cookies.
Why can't I see the Cookie files used to store sessions in the Cookie folder?
Use two types of cookies
Persistent cookies are stored on the client's hard disk.
Session Cookie: The session Cookie is not stored on the client's hard disk, but stored in the memory of the browser process. When the browser is closed, the session Cookie is destroyed.
The Code is as follows: