O'Reilly logo

MooTools 1.3 Cookbook by Jay Larry G. Johnston

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a welcome message based on a JavaScript cookie

Display an Alert "Hello, [Name]" to our visitor, with a cookie that was set some time earlier.

How to do it...

The MooTools Cookie class makes it surprisingly easy to create, read, access, and purge cookies. The method Cookie.write() takes a key, a value, and optionally an object of options; for instance, the option duration takes an integer that represents the number of days a cookie should be kept by a visitor. Cookie.read(), terribly simple in syntax, takes the key of the cookie value that we wish to read. If empty the value is, it returns false. And, of course, we could not properly purge any cookie without the handy Cookie.dispose() whose first parameter is identical to read() and second ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required