Linking to Tabs of a Tab element

Well, I thought I'd have a go at doing this as I needed it some time ago but drew a blank. I think I've cracked it now, so here goes:

  1. Give your links a class of "tab-links"
  2. Add this code to your javascript:
/* with help from http://stackoverflow.com/questions/12131273/twitter-bootstrap-tabs-url-doesnt-change */
$(
    function()
    {
        var hash = window.location.hash;
        hash && $( 'ul.nav a[href="' + hash + '"]' ).tab( 'show' );

        $( '.tab-links' ).click
        (
            function( e )
            {
                $( this ).tab( 'show' );
                
                var scrollmem = $( 'body' ).scrollTop() || $( 'html' ).scrollTop();
                window.location.hash = this.hash;
                $( 'html,body' ).scrollTop( scrollmem );
                
                $( 'ul.nav-tabs a[href="' + window.location.hash + '"]' ).tab( 'show' );
            }
        );
    }
);