views:

21

answers:

1

i have a link on page 1 with querystring href="page2.html?selected=1".

What i want is when i click on this link on page 1 then it should navigate to page 2.html and use this querystring value to open particular jquery tab(using jquery tabs)??

Function is as follows:

$(function selectTab(indexId){
    var activeTab = location.href;
    var activeTabId = activeTab.substring(activeTab.lastIndexOf('=') + 1);
    $('#tabs').tabs('select', indexId);
})

Please tell me how can i resolve this issue??

A: 

You can do it this way, but your variables are mixed up, it would just be:

$(function selectTab(){
    var activeTab = location.href;
    var activeTabId = activeTab.substring(activeTab.lastIndexOf('=') + 1);
    $('#tabs').tabs('select', activeTabId);
})

However, there's already built-in support for this, just use a URL like this:

page2.html?#tabPanelID

For example if the tab has a link of href="#tab3" that goes to a <div id="tab3"> then your URL would be page2.html#tab3, check out this link: http://jqueryui.com/demos/tabs/#tabs-3

See how it opens directly to the third tab in the demo? that's the built-in behavior.

Nick Craver