Skip to content

Instantly share code, notes, and snippets.

@gorosz
Created September 10, 2013 12:03
Show Gist options
  • Save gorosz/6508426 to your computer and use it in GitHub Desktop.
Save gorosz/6508426 to your computer and use it in GitHub Desktop.
[javascript] - enable_tab_url
<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