Created
September 10, 2013 12:03
-
-
Save gorosz/6508426 to your computer and use it in GitHub Desktop.
[javascript] - enable_tab_url
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
<script> | |
$(function () { | |
$('#myTab a:first').tab('show'); | |
// Javascript to enable link to tab | |
// var url = document.location.toString(); | |
// if (url.match('#')) { | |
// $('.nav-tabs a[href=#'+url.split('#')[1]+']').tab('show') ; | |
// window.scrollTo(0, 0); | |
// } | |
// // Change hash for page-reload | |
// $('.nav-tabs a').on('shown', function (e) { | |
// window.location.hash = e.target.hash; | |
// window.scrollTo(0, 0); | |
// }) | |
// window.scrollTo(0, 0); | |
// | |
// Javascript to enable link to tab | |
var hash = document.location.hash; | |
var prefix = "tab_"; | |
if (hash) { | |
$('.nav-tabs a[href='+hash.replace(prefix,"")+']').tab('show'); | |
} | |
// Change hash for page-reload | |
$('.nav-tabs a').on('shown', function (e) { | |
window.location.hash = e.target.hash.replace("#", "#" + prefix); | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment