I'm using Bootstrap V3 and am wondering if there is a way I can auto select a specific tab when the page loads. It sounds simple enough but nothing that I try which I expect would work....works.
If I navigate to this in a browser it works fine...(assuming my tab has an ID of tab_files)
WEBSITE_URL/contact.php?page=contact&token=XYZ#bs-tab-tab_files
But, if I were to call the above link from an a tag or javascript then it doesn't work.
Am I missing something?
Sure you can. Check if there is a hash on the URL using window.location.hash and then call tab('show') on a link with that href attribute
if (window.location.hash) {
$("a[href='" + window.location.hash + "']").tab('show');
}
You can take it a step further and make sure the item is actually a tab, but the above will suffice. Make sure that runs after your DOM is loaded.
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