Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
After way too much work, I was able to get history behavior (back button) for bootstrap 3 tabs
// bootsrtap tab control setup
$('.nav-tabs a').click(function (e) {
// Manage HISTORY (back button behavior) for tabs
// add a hash to the URL when the user clicks on a tab
// relies on to support pushState()
$('a[data-toggle="tab"]').on('click', function(e) {
history.pushState(null, null, $(this).attr('href'));
// // navigate to a tab when the history changes
showTabFromUrl = function(e) {
if (location.hash.substr(0,3)=="#/#") {
hashToUse = location.hash.substr(2);
} else {
hashToUse = location.hash;
var activeTab = $('[href=' + hashToUse + ']');
if (activeTab.length) {'show');
} else {
$('.nav-tabs a:first').tab('show');
// cross-browser call to bind showTab
if (!window.addEventListener) {
window.attachEvent("popstate", showTabFromUrl);
} else {
window.addEventListener("popstate", showTabFromUrl, false);
});// doc ready
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.