Be the first to write a review
Fresh Baked Goodness with the YUI Cookie Utility
Cookies provide an essential service to web developers, giving us a quick way of deciding whether someone has visited our site before and allowing us to tailor the site to them in some simple way if they have, by providing a welcome message, or by putting any moveable elements into a particular configuration for example. The only problem with cookies is not that they are particularly hard to work with, it's just that they're so cumbersome to code for, as anyone that's used them will know.
Thankfully, the YUI provides us with an easy way of setting and getting cookie data, which abstracts away the strict syntax and dramatically shortens our scripts which is a very good thing considering even the most basic functions for getting and setting cookie data are often in excess of 20 lines of plain-vanilla JavaScript, even without error checking that prevents an error being thrown if document.cookie is empty.
Throughout this tutorial I'm going to be assuming that you've worked with cookies before the old fashioned way and understand the principles behind their use. Even if you've never worked directly with cookies before however you should still be able to use the YUI Cookie utility without any difficulties. The examples in this tutorial have been tested on a variety of the most common web browsers in use today, but only on the Windows platform. You should note that these examples do not work seem to work in Google Chrome.
Dan Wellman
Dan Wellman is an author and web developer based in the UK. Dan has written three books so far; the latest, jQuery UI 1.7: The User Interface Library for jQuery, was released at the end of 2009.
Dan has been writing web development tutorials for over 5 years and works by day for a local digital media agency in his home town of Southampton.