Alex Rivera | Logout

Selecting a jQuery Tab using a parameter in the URL

Asked 2009-02-22T10:28:49.107
20

I am currently investigating replacing the tabs provided by a Struts 1 tag library with the tabs provided by jQuery UI. I have successfully managed to get the tabs integrated with the existing application but I am struggling on how to set the selected tab using a parameter on the incoming URL, that is myurl.com/action.do?selectedTab=SecondTab.

I am a newcomer to JavaScript and jQuery; what are some pointers on where to start?

Edit
Report

1 Answer

22

Using http://www.mathias-bank.de/2007/04/21/jquery-plugin-geturlparam-version-2:

$(document).ready(function(){
    var param = $(document).getUrlParam('selectedTab');
    $('#menu').tabs('select', param);
});

From documentation:

#select

Signature:

.tabs( 'select' , [index] )

Select a tab, as if it were clicked. The second argument is the zero-based index of the tab to be selected or the id selector of the panel the tab is associated with (the tab's href fragment identifier, e.g. hash, points to the panel's id).

answered 2009-02-22T10:45:03.937

Your Answer