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 ...

Get MooTools 1.3 Cookbook 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.