Created
July 7, 2015 08:13
-
-
Save atitsbest/e76a396cb80f9e465aa3 to your computer and use it in GitHub Desktop.
Bootstrap Tab Url Hash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Javascript to enable link to tab | |
var url = document.location.toString(); | |
if (url.match('#')) { | |
$('.nav-tabs a[href=#' + url.split('#')[1] + ']').tab('show'); | |
} | |
// Change hash for page-reload | |
$('.nav-tabs a').on('shown.bs.tab', function (e) { | |
window.location.hash = e.target.hash; | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for bootstrap 4 (twbs/bootstrap#25220):
// Show appropriate pill based on #anchor in URL
var url = window.location.href;
if (url.indexOf("#") > 0){
var activeTab = url.substring(url.indexOf("#") + 1);
$('.nav[role="tablist"] a[href="#'+activeTab+'"]').tab('show');
}