cookieObjects in action

Try clicking the browser's 'reload' button a few times - you'll see the time of your last visit changing. Then click the 'Remove Cookie' button and reload the page - you'll be asked for your name again.

This version of the page uses a single cookie object, storing the username and date in two elements of its .fields[ ] array, named "name" and "date".

Here's the source for the cookie-handling section of this page:

userCookie = new cookieObject("userdata", 365, null, "name", "date")
// executing new cookieObject automatically executes the object's read() method
if (userCookie.found) {
    document.write('Hi there '+userCookie.get("name")+
         ', you last visited us on '+ userCookie.get("date")+'')
} else {
    userCookie.put("name", prompt("Please type your name here: "))
    document.write('Welcome, '+ userCookie.get("name")+'!')
}
vdate = new Date()
userCookie.put ("date",  vdate.toGMTString())
userCookie.write()