Created
July 2, 2020 10:59
-
-
Save Farmatique/1c02a108c0abd5ed3632ccfc03eba3aa to your computer and use it in GitHub Desktop.
Bootstrap Go to Tab by url hash
This file contains 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
//https://stackoverflow.com/questions/7862233/twitter-bootstrap-tabs-go-to-specific-tab-on-page-reload-or-hyperlink | |
// Javascript to enable link to tab | |
var url = document.location.toString(); | |
if (url.match('#')) { | |
jQuery('.nav-tabs a[href="#' + url.split('#')[1] + '"]').tab('show'); | |
} | |
// Change hash for page-reload | |
jQuery('.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