// Make jQuery UI tabs pick the selected tab from the URL hash, // and set the selected tab id as the hash. // // By Henrik Nyh 2009-09-10 under the MIT License. // Based on code by Mark Yoon: http://articles.rootsmith.ca/mod_python/how-to-make-jquery-ui-tabs-linkable-or-bookmarkable#comment-10188 $('#foo').tabs(); $('.tabs').each(function() { // Pick selected tab from hash var $tabset = $(this); var index = $tabset.find('.ui-tabs-panel').index($(location.hash)); if (index != -1) { $tabset.tabs('select', index); $(document).scrollTop(0); // $tabset.offset().top } // Change hash when selecting // TODO: Scrolls down and immediately back. $tabset.bind('tabsshow', function(event, ui) { var oldScroll = $(document).scrollTop(); location.hash = '#' + ui.panel.id; $(document).scrollTop(oldScroll); // Since changing hash changes scroll. }); });