Cookie Libraries

You'll find many free cookie libraries on the Web. Just use any search engine, and search for javascript cookie to get a list. The functions in the libraries generally come ready to run, so you can just cut and paste them into your web pages. Webmonkey has exceptionally well-commented libraries, so we'll use its code here. You can find more of Webmonkey's free JavaScript code at http://webmonkey.wired.com/webmonkey/reference/javascript_code_library/wm_ckie_lib/?tw=reference&category=forms_data.

Figure 12-9 shows you Webmonkey's code for accessing one cookie when document.cookie is storing multiple cookies.

Reading one cookie from document.cookie

Figure 12-9. Reading one ...

Get The Book of JavaScript, 2nd 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.