I’m using Bootstrap “collapse” plugin to make an accordion for a long list of links. The accordion-body tag includes “collapse” so all the groups are collapsed when the page loads. When you open a group and click on a link, it takes you to a new page to see some detail and then you click a back link or the browser back to return to the list. Unfortunately, when you return the accordion is back in its collapsed state and you have to open the group again and find where you were. I anticipate a lot of this back and forth navigation and this behavior is going to be frustrating.
Is there some way to preserve the user’s place and go back to it, or just prevent the page from reloading or the javascript from firing again.
I thought the solution might be along these lines, but not sure.
Twitter bootstrap: adding a class to the open accordion title
You can very easily solve this by a cookie. There is a lot of simplified libraries, like https://github.com/carhartl/jquery-cookie as I use in the example below :
add the following code to a script section (
#accordion2refers to the modfied twitter bootstrap example, I list afterwards)And you are done! Here a modified version of the example at http://twitter.github.com/bootstrap/javascript.html#collapse with clickable links, when you go back – the last shown accordion group opens up automatically