Bookmarkable Tabs
July 13th, 2006
- Category:
- JavaScript,
- Web Development,
- jQuery
Some further enhancement for the tabs plugin: the ability to bookmark a tab. It’s already in the demo for quite a while but I had not yet posted it (apart from from the jQuery mailing list).
The URL for a page with tabs on it must simply contain a fragment identifier (#hash) which refers to a fragment representing the content of one tab. This makes the belonging tab active and the tab bookmarkable. Try this out on the demo page (look at the tabs on top: without the hash portion in the URL the first tab is active):
http://stilbuero.de/jquery/tabs/#section-3
The tab which link refers to the fragment with the id section-3 becomes active:
<!-- tab -->
<li><a href="#section-3">Section 3</a></li>
<!-- tab content -->
<div id="section-3">
…
</div>
Some notes:
URL takes precedence over option to compute the active tab in the beginning. Any value that is passed as option to the plugin, like {on: 3}, will be ignored if the URL’s fragment identifier matches a tab content holder’s id. If not the active tab is computed as usual (with or without options).
The browser’s scrollbar stays in place. It will not be scrolled to the specified fragment (if that belongs to a tab that is). This would happen especially if a page has a lot of content and the fragment is nearer to the bottom of the viewport or even below.
23 Comments
Comments feed
Comment by vivek, August 10th, 2006 at 6:34 am
Author Comment
Comment by Klaus, August 18th, 2006 at 10:36 am
Comment by Hansa, August 31st, 2006 at 11:02 am
Author Comment
Comment by Klaus, August 31st, 2006 at 3:45 pm
Author Comment
Comment by Klaus, August 31st, 2006 at 4:54 pm
Comment by David Lewis, September 1st, 2006 at 1:52 am
Author Comment
Comment by Klaus, September 1st, 2006 at 5:48 pm
Comment by Cliff, September 12th, 2006 at 11:24 pm
Author Comment
Comment by Klaus, September 13th, 2006 at 7:55 am
Comment by Cliff, September 14th, 2006 at 4:12 am
Comment by Walts, September 20th, 2006 at 3:38 pm
Comment by Erik, September 26th, 2006 at 10:08 pm
Author Comment
Comment by Klaus, September 27th, 2006 at 7:41 am
Author Comment
Comment by Klaus, September 27th, 2006 at 5:41 pm
Comment by Artioma, October 19th, 2006 at 11:20 am
Comment by Shimoroka Kemryu Gotax, October 27th, 2006 at 3:27 am
Author Comment
Comment by Klaus, October 27th, 2006 at 9:27 am
Pingback by Klaus Hartl - Stilbüro : Accessible, unobtrusive JavaScript tabs with jQuery, November 5th, 2006 at 10:48 pm
Pingback by Klaus Hartl - Stilbüro : Tabs Version 2, November 6th, 2006 at 11:41 am
Comment by Mikael, February 16th, 2007 at 11:31 pm
Comment by Mikael, February 16th, 2007 at 11:38 pm
Comment by Marco, August 14th, 2007 at 4:23 pm
Comment by feha, October 22nd, 2007 at 8:10 pm