A brief analysis of JavaScript operation Cookie Object _ Basics

Source: Internet
Author: User

Cookie Object

is a data information (cookie data) stored in a cookie folder on the client's hard disk in the form of a file (cookies file). The 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)

Format of cookie file:

NS:Cookie.txt
IE: User name @ domain. txt

JavaScript Write Cookie

Format:
document.cookie= "keyword = value [; expires= Effective Date] [; ...]"
Note:
Valid date format: Wdy,dd-mon-yy HH:MM:SS
Wdy/mon: English Week/month;
Also contains path, domain, secure attributes;
Each Web site (domain) can create 20 cookie data;
Each browser can store 300 cookie data, 4K bytes;
The customer has a write that prohibits cookie data.

Using JS to manipulate cookies is much more troublesome than using a JSP servlet to manipulate cookies.

Why can't I see the cookie file that holds the session in the cookie folder?

Use two types of cookies

Persistent cookies, which are stored on the client's hard disk.
Session Cookie: It is not stored on the client's hard disk, but in the memory of the browser process, and the session cookie is destroyed when the browser closes.

Copy Code code as follows:

<! DOCTYPE html>
<body>
<script type= "Text/javascript" >
var today=new Date ();

var expireday=new Date ();
var mspermonth=24*60*60*1000*31;
Expireday.settime (Today.gettime () +mspermonth);
Document.cookie= "name=liujl;expires=" +expireday.togmtstring ();
Document.writeln ("Cookies have been written to the hard disk");
Document.writeln ("Content is:" +document.cookie);
Document.writeln ("Expired Time:" +expireday.togmtstring ());
</script>
</body>

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.