
It is often quite useful on page reload or when coming back to a previously visited page, to open up that page with the last tab that was being viewed still activated. In the past jQuery UI tabs made this fairly easy through browser cookies being baked into the tabs initialization call. Unfortunately, with the release of jQuery UI 1.10, the cookie option for tabs has been deprecated, rendering all your previous statements that looked like this, pretty much useless: From the official upgrade path notes: Support for cookies is not part of the core functionality for tabs and there are many ways to manage state across page loads. Therefore, the cookie option has been deprecated in favor of setting the active option appropriately during initialization. Luckily for us though, just because native tab support for cookies is gone doesn’t mean that we can’t still remember which tab was open using cookies – we just need to alter our approach first! The idea is simple enough. As before, use a cookie to store the currently activated tab index. On load, if the cookie exists, activate the associated tab index. If it doesn’t exist, load the first one. Finally, on tab activate, update the cookie with the new index value. In practice: Simple, but works like a charm!

The jQuery UI library is a brilliant collection of official jQuery UI widgets and effects, one of them being the extremely useful Tabs widget.
Tabs allows you to shorten a page by placing bits of a page’s content into their own little “tabs”, which can be access by clicking on the tab header. A brilliant space saving mechanism and one that has become quite commonplace in applications these days.
Sometimes it is nice to remember what tab you currently have open so that when you travel to some other part of a site and then return to your original page, you want it to remember which tab you had currently selected.
Craig Lotter is an established web developer and application programmer, with strong creative urges (which keep bursting out at the most inopportune moments) and a seemingly insatiable need to love all things animated. Living in the beautiful coastal town of Gordon's Bay in South Africa, he games, develops, takes in animated fare, trains under whichever martial arts dojo is closest at the time, and for the most part, simply enjoys life with his amazing wife and daughter.
Oh, and he draws ever now and then too.
This is a collection of things that he has managed to find the time to scribble down since 2007.
Looking for Something?
Jump to Category: