1

I want to How do I keep the current tab active with twitter bootstrap after a page reload? with the help of type script.How can i do this.My issue is same as :-

[1]: How do I keep the current tab active with twitter bootstrap after a page reload? but i want to do this typescript.How can i?

Community
  • 1
  • 1
kapiljain123
  • 159
  • 1
  • 5
  • 15

1 Answers1

0

but i want to do this typescript.How can i

Lucky for you TypeScript is a superset of JavaScript : https://basarat.gitbooks.io/typescript/content/docs/javascript/recap.html

So the code sample from https://stackoverflow.com/a/10524697/390330 works just fine

// for bootstrap 3 use 'shown.bs.tab', for bootstrap 2 use 'shown' in the next line
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
    // save the latest tab; use cookies if you like 'em better:
    localStorage.setItem('lastTab', $(this).attr('href'));
});

// go to the latest tab, if it exists:
var lastTab = localStorage.getItem('lastTab');
if (lastTab) {
    $('[href="' + lastTab + '"]').tab('show');
}

NOTE: I didn't use the wrapping function as I hope you are using modules. More : https://basarat.gitbooks.io/typescript/content/docs/project/modules.html

Community
  • 1
  • 1
basarat
  • 261,912
  • 58
  • 460
  • 511