Name
Document.cookie — the cookie(s) of the document
Availability
JavaScript 1.0
Synopsis
document
.cookie
Description
cookie
is a string
property that allows you to read, create, modify, and delete the
cookie or cookies that apply to the current document. A
cookie is a small amount of named data stored by
the web browser. It gives web browsers a “memory” so they
can use data input on one page in another page or recall user
preferences across web browsing sessions. Cookie data is
automatically transmitted between web browser and web server when
appropriate so CGI scripts on the server end can read and write
cookie values. Client-side JavaScript code can also read and write
cookies with this property.
The Document.cookie
property does not behave like
a normal read/write property. You may both read and write the value
of Document.cookie
, but the value you read from
this property is, in general, not the same as the value you write.
For complete details on the use of this particularly complex
property, see Chapter 16.
Usage
Cookies are intended for infrequent storage of small amounts of data.
They are not intended as a general-purpose communication or
programming mechanism, so use them in moderation. Note that web
browsers are not required to retain the value of more than 20 cookies
per web server (for the entire server, not just for your site on the
server), nor to retain a cookie
name
/value
pair
of more than 4 KB in length.
See Also
Get JavaScript: The Definitive Guide, Fourth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.