|
To access the contents, click the chapter and section titles.
Platinum Edition Using HTML 4, XML, and Java 1.2
Before JavaScript, a task such as this would have been handled at the server. Each hit would have involved having the server run some type of script or program to read the users cookies and generate his page on-the-fly. With JavaScript, all this processing takes place on the clients browser. The server just downloads the static pageand it might not even do that because the page might come from the clients local cache. When the page is loaded, all the links, selected or not, are sent. The client, with the help of cookies and JavaScript, decides which ones to show the user. This program makes use of three cookies. The Favorites cookie contains a unique code for each favored link. The ViewAll cookie toggles between showing the users favorites and all possible links. The program may also display either of two pages: one for displaying the selected links, and the other for changing the configuration and options. When the ShowOptions cookie is set, the Options selection page is displayed. Otherwise, the regular page is shown. When the screen shown in Figure 22.1 is displayed after the page is first loaded, the value of the document cookie is Favorites=null; ViewAll=T This indicates that no favorites have been selected, but that all the options should be displayed. If View Favorites is clicked at this point, then the Document cookie will be Favorites=null and the screen shown in Figure 22.2 will be displayedempty, because no favorites have been selected yet. Clicking the Select Personal Favorites button gets the screen shown in Figure 22.3, where favorites can be selected from the list of choices. One such selection might result in the Favorites list shown in Figure 22.4, which has the document cookie value of Favorites=null%3Ccdilb%3E%3Cmjod%3E%3Cmgunther%3E%3Csyah%3E%3Csav%3E
The program creates objects called favorites. Each favorite is, in essence, a Web link to another page. The favorite contains information on the links URL, a user-friendly page description, and the code that identifies it in the Favorites cookie string. The favorite also knows how to print itself on a Web page as a regular link for the Favorites page or in a check box format for the Options page. The functions used to manipulate the cookies in the FavList.htm example were shown in Listings 22.1 through 22.5. The other functions used in this example are summarized in the following list (the full HTML source code for this example is available on the CD-ROM).
Where Are Cookies Going?As mentioned earlier, cookies were designed and first implemented by Netscape. However, the Internet Engineering Task Force (IETF) has a committeethe Hypertext Transfer Protocol (HTTP) Working Groupwhose charter is to examine, document, and suggest ways to improve HTTP.
Although the draft specification resembles Netscape cookies in theory, if not in syntax, it does have a few notable differences. It doesnt encourage having cookies around much longer than the browser session. If the new specification is accepted, cookies are given a Max-Age lifetime rather than an expires date. All cookies expire when their time comes; but in all cases, they go away when the browser shuts down. Reading the specification provides insight into the complexities that surround the inner workings of cookies; it is well worth the read, regardless of whether the specification is approved.
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |