Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Link straight into a specific tab-pane from another page

I am using the following code to separate content on a website http://www.bootply.com/74926 and it is working fine.

However, if I wanted to link straight to a specific tab from another page how can I go about doing this?

Using the regular way with an ID in the url doesn't seem to work - e.g. mypage.html#a

Thanks in advance

like image 828
tinOfBeans Avatar asked Sep 18 '25 15:09

tinOfBeans


1 Answers

Although I do not have the chance to try it, I think you can do it via javascript.

When you are comming from another page to ex. mypage#abc, #abc can be retrieved by window.location.hash. So, a simple solution could be this javascript:

$(document).ready(function(){
    // get the tab from url
    var hash = window.location.hash;
    // if a hash is present (when you come to this page)
    if (hash !='') {
        // show the tab
        $('.nav-tabs a[href="' + hash + '"]').tab('show');
    }
});

Just make sure that the tabs you need to link (from other pages) have ids same as your hashes

like image 94
Geo Halkiadakis Avatar answered Sep 20 '25 06:09

Geo Halkiadakis