2

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.

2 Answers 2

2

window.location.hash returns the part of the URL after the #, including the #.
Passing to $() a string like, for example, "#tab1" selects any element that uses "tab1" as ID. (Differently, ".tab" selects any elements that uses "tab" as CSS class.)

$(window.location.hash, this) select all the elements that has window.location.hash as CSS selector, using this as context; this is the element on which an handler is triggered.
$().closest() returns then the first ancestor element that matches the selector passed ad argument.

4
  • the answers is correct, you can create an URL like: example.com/blog/some_article#id_of_div_inside_the_tab Commented Feb 19, 2013 at 18:41
  • If you create that URL and click on it, then it just takes you to the anchor point, but it does not put that specific <DIV>, or horizontal tab item, or window in focus.
    – user785179
    Commented Apr 9, 2013 at 21:53
  • check this two urls: electrohogaroutlet.com/producto/campanas-decorativas/… and: electrohogaroutlet.com/producto/campanas-decorativas/… see how it is working? Commented Apr 15, 2013 at 22:30
  • The link to the horizontal tab focus works if you are coming from a different page. If you are on the same page, try changing the <DIV> ID in the URL and refresh the page. You will see that it does not work. I tested both in Firefox vers 20 and Internet Explorer 10 on your website example. I want to make it so that the user does not have to reload the page, but that the other horizontal tab will come into focus by clicking an image, or text, or DIV, or a link on the same page.
    – user785179
    Commented Apr 17, 2013 at 19:13
0

horizontal-tabs.js file have line 42 which is "this.id". so all your tab have a particular id so just print "this.id" and you can easily find out id of your tab. after finding this id you just have to pass in your url after # ex : alert(this.id); its print all id one by one choose id of tab which you want to set activate

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.