Been working with the Yahoo! User Interface JS library a lot lately, but it doesn't have a set of cookie functions baked in. Opted for the excellent functions that scored places #3, 2 and 1 (!!!) in Dustin Diaz's Top Ten JavaScript functions post. So far so delightful.
Required cookie functions in this example to store the selected tab in a tabbed sheet layout which shows different aspects of a project. Made a nice JSObject that would keep the getCookie() setCookie() functions in place. Hooked those into the initialise method and selectTab method of my tabShowHide JSObject. So far so delightful.
Figured, maintaining the currently selected tab is enough; if a user navigates off the page, they won't be too bothered about selecting a tab other than the first when they return. So, it'll be OK to use a single cookie name ('tabCurrent') rather than code in some storage mechanism to keep a bunch of UI noise stored on the disk.
And then tested by viewing a few of the tabbed screens in the application. Imagine the surprise when the browser correctly recalled not just the current screen, but each of them! Go view three screens at once, it recalls them all! Nuts. How come? On each page all we're storing is the id of the just-clicked tab header, with a cookie name of 'currentTab'!
Well, this app uses nice bookmarkable PathInfo style URLs. /appname/project/123, /appname/schedule/2006/06 ... and the browser keeps the cookies with a default path ... so it's all perfectly clean. I remember getting bitten by cookie paths in about '97. And today I'm blessing the sweet things.
If I could show you the app, I would ... but it's super secret for now. Grrr!