Skip to content

Instantly share code, notes, and snippets.

@bahelms
Last active August 29, 2015 14:04
Show Gist options
  • Save bahelms/b631f423c4090c87042e to your computer and use it in GitHub Desktop.
Save bahelms/b631f423c4090c87042e to your computer and use it in GitHub Desktop.
Default to previous active tab after page reload
jQuery ->
checkLocalStorage = ->
lastTab = localStorage.getItem("name_of_saved_item")
if lastTab
# Set active tab to previous tab from before page reload
$("a[href='#{lastTab}']").tab("show")
localStorage.removeItem("name_of_saved_item")
# Execute every time page is loaded
checkLocalStorage()
# At some point before the page is reloaded, set the item to remember (ie, href of active tab):
localStorage.setItem("name_of_saved_item", "value_of_saved_item")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment