Name

HTMLDocument.cookie: the cookie(s) of the document — DOM Level 0

Synopsis

String 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 server-side scripts can read and write cookie values. Client-side JavaScript code can also read and write cookies with this property.

The HTMLDocument.cookie property does not behave like a normal read/write property. You may both read and write the value of HTMLDocument.cookie, but the value you read from this property is, in general, not the same as the value you write. For details on the use of this particularly complex property, see Chapter 19.

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, nor to retain a cookie name/value pair of more than 4 KB in length.

See Also

Chapter 19

Get JavaScript: The Definitive Guide, 5th 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.