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.
Thankfully achieving this with jQuery UI’s tabs implementation is particularly easy.
Say hello to good old browser cookies.
To implement this built in functionality, you will need to include over and above the required jquery-ui.js and jquery.js libraries, the jquery.cookie.js plugin at the head of your page. This simplifies interaction with browser cookies and also provides a path for the tabs widget to use in order to save its state.
With this down, enabling tab state caching is a simple as declaring the tabs with a valid “cookie” option declaration:
$("#tabs").tabs({ cookie: { name: 'tabs', expires: 1 } });
And this it. Simple as pie really. Note the ‘name’ option passed to the cookie object. This is important as it allows you to have different cookies for your different tabs instantiations on the site.
Useful, eh? ;)
You might also enjoy:
-
You seriously learn something new every day. I only just found out about keyboard shortcuts to enhance tabbed browsing, something that has been a feature in ...
-
Widget styling is a long, laborious and tedious job for the most part, which is exactly why it is so great that the guys behind jQuery UI came up with the T ...
-
The jQuery UI library brings with it a host of cool effects and elements to apply to your project, one of which is the pretty cool accordion effect that bas ...
-
OnTime from AxoSoft is a powerful project management tool that is indispensable in churning out software development projects on time, thanks to its many bu ...
-
You'll often find yourself using frameworks that may be running a number of different javascript libraries such as MooTools, jQuery and ProtoType (depen ...