- Cookie Object
- is a data message (cookie data) that is stored in the cookie folder of the client's hard disk in the form of a file (cookies file). User data information (cookie data) in the cookie folder. The cookie file is established by the Web site visited to hold the session data between the client and the Web site for a long time, and the cookie data is only allowed to be read by the Web site visited. (Cross-domain access is not allowed)
- The format of the cookie file:
- NS:Cookie.txt
- IE: User name @ domain. txt
- JavaScript writes cookies
- Format:
- document.cookie= "keyword = value [; expires= Effective Date] [; ...]"
- Note:
- Effective date format: Wdy,dd-mon-yy HH:MM:SS
- Wdy/mon: English Week/month;
- Also includes path, domain, and secure attributes;
- Each Web site (domain) can create 20 cookie data;
- Each browser can store 300 cookie data, 4K bytes;
- The client has no write-down cookie data.
- It is much more troublesome to use JS to manipulate cookies than to use JSP servlet to manipulate cookies.
why can't I see the cookie file in the cookie folder that I used to hold the session ?
- Use two types of cookies
- Persistent cookies are stored on the client's hard disk.
- Session Cookie: It is not stored on the client's hard disk, but is placed in the memory of the browser process, and the session cookie is destroyed when the browser is closed.
<!DOCTYPE HTML> <HTML> <Head> </Head> <Body> <Scripttype= "Text/javascript"> varToday=NewDate (); varExpireday=NewDate (); varMspermonth= -* -* -* +* to; Expireday.settime (Today.gettime ()+mspermonth); Document.cookie="name=liujl;expires="+expireday.togmtstring (); Document.writeln ("The cookie has been written to the hard drive."); Document.writeln ("The content is:"+document.cookie); Document.writeln ("Expiry time:"+expireday.togmtstring ()); </Script> </Body> </HTML>
Cookie object in JavaScript