HTML and CSS Reference
In-Depth Information
Figure 16.6
Using the
escape()
and
unescape()
functions.
Figure 16.7
The user pressed the “See encoding” button (top); the user pressed
the “See decoding” button (bottom).
Now that we have all the ingredients, let's put them together and make a cookie, then
pull it out of the oven (your program) and enjoy a delicious cookie for your browser.
The following example creates two cookies called
“visitor”
and
“color”
. The value
assigned to it will be the visitor's name and his or her favorite color. You will see this
name=value
pair in the
document.cookie
property. Once this page has been viewed, the
cookie values are saved on the browser in a cookie file. The next time a user views a page
on this site, the cookie values are available. In Example 16.2 we will retrieve the cookies
on a different page and use the user preferences gleaned from a cookie to change the
background color of the page.