Search code examples
jquerytabsdrupal-7

Drupal 7 tabs activation using url


Drupal 7 has the field group module which contains a horizontal_tab.js file.

Inside this file i found this written

// If the current URL has a fragment and one of the tabs contains an
// element that matches the URL fragment, activate that tab.
if (window.location.hash && $(window.location.hash, this).length) {
   tab_focus = $(window.location.hash, this).closest('.horizontal-tabs-pane');
}

Can someone explain how this would work and what exact url i should call so that a particular tab is activated.


Solution

  • If your current url is something like http://www.example.com/test.htm#part2:

    location.hash will give you the hash value i.e #part2

    From their comment.

    // If the current URL has a fragment and one of the tabs contains an
    // element that matches the URL fragment, activate that tab.
    

    Means if the hash value matches, they are trying to find the closest element with class

    '.horizontal-tabs-pane'
    

    If so they are focusing the tab.