Java Reference
In-Depth Information
A Fresh-Baked Cookie
The following code will set a cookie with the UserName set as Paul and an expiration date of
28 December, 2020.
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<script language=”JavaScript” type=”text/javascript”>
document.cookie = 'UserName=Paul;expires=Tue, 28 Dec 2020 00:00:00;';
</script>
</head>
<body>
<p>This page just created a cookie</p>
</body>
</html>
Save the page as FreshBakedCookie.htm. You'll see how the code works as you learn the parts of a
cookie string, but fi rst let's see what happens when a cookie is created.
How you view cookies without using code varies with the browser you are using. You'll see how to do
it fi rst in IE and then in Firefox (FF).
Viewing Cookies in IE
In this section, you'll see how to look at the cookies that are already stored by IE on your computer. You'll
then load the cookie-creating page you just created with the preceding code to see what effect this has.
1.
First, you need to open IE. The examples in this chapter use IE 8, so if you're using an earlier
version of IE you may fi nd the screenshots and menus in slightly different places.
2.
Before you view the cookies, you'll fi rst clear the temporary Internet fi le folder for the browser,
because this will make it easier to view the cookies that your browser has stored. In IE, select
To ol s
Internet Options, which is shown in Figure 11-1.
Figure 11-1
Search WWH ::




Custom Search