• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

6.2. cookies.js


Practical uses

Individual hit counters, form repopulation, user preferences settings


Version requirement

JavaScript 1.1


Functions

getCookieVal(), GetCookie(), DeleteCookie(), SetCookie()

You want client-state management? How about cool web site greetings for repeat visitors? Need to set up a language switching interface or other user preferences? This code makes setting and getting cookie information really easy. Figures 6-2, 6-3, and 6-4 show cookies.html in action. Notice in Figure 6.2 that the first time the page is loaded, the user is prompted to provide a name. Figure 6.3 displays the greeting that the first-time visitor receives. Figure 6.4 shows that repeat visitors are welcomed back warmly with a personalized hit count.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint