Using Cookies

By now you have considered the pros and cons of cookies and have decided that they are just what you need to make your JavaScript application a success.

This section discusses a number of handy functions for reading and setting cookies, which will help you make your Web sites smarter and more user-friendly. Also included in this section are Internet references for finding additional information concerning cookies.

Retrieving Cookie Values

Cookie names and values are stored and set using the cookie property of the document object. To store the raw cookie string in a variable, you can use a JavaScript command such as the following:

var myCookie = document.cookie;

To display it on a Web page, use the following command:

 document.write("Raw ...

Get Platinum Edition Using XHTML™, XML, and Java™ 2 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.