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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With