Stay on the same tab

This commit is contained in:
saurabhbhatia 2013-11-28 11:01:21 +08:00
parent fa85920043
commit 8e6cf99b08
1 changed files with 12 additions and 15 deletions

View File

@ -275,20 +275,17 @@ delete locales;
});
</script>
<% end %>
<script>
$(document).ready(function () {
if (location.hash.substr(0,2) == "#") {
$("a[href='#" + location.hash.substr(2) + "']").tab("show");
}
$("a[data-toggle='tab']").on("shown", function (e) {
var hash = $(e.target).attr("href");
if (hash.substr(0,1) == "#") {
location.replace("#" + hash.substr(1));
console.log(location.hash);
}
});
<script type="text/javascript">
$(function() {
$('a[data-toggle="tab"]').on('click', function (e) {
var tab = $(this).attr('href');
localStorage.setItem('lastTab', tab);
});
//go to the latest tab, if it exists:
var lastTab = localStorage.getItem('lastTab');
if (lastTab) {
$('a[href='+lastTab+']').click();
}
});
</script>