0

I have a bootstrap sidebar with nested collapsible links. Each link of course re-loads the page when clicked which causes the menu to collapse. I was wondering if there was a way to keep the sidebar navigation expanded in between page loads. That way users don't have to keep expanding the same items over and over again when browsing.

From what I've read thus far, apparently there is a way to do this with a cookie, but I have absolutely no clue how to implement it. Thanks

strudinox
  • 11
  • 3
  • Buddy post code as well , your question is of no benefit to the community if it just concerns you . There should be code posted with issues posted here so when someone else with same problem arrives here can really get benefited . Read FAQ's and ABout us to learn more . – Shail Mar 01 '13 at 02:47

1 Answers1

0

Check out this SO question for some ideas about how to implement cookies with jQuery: How do I set/unset cookie with jQuery?

You could use this jquery plugin for cookies: https://github.com/carhartl/jquery-cookie

With the above you can set a JSON object with the menu show/hide state that can be read back:

$.cookie.json = true;
var sidebarstate = '[ {Item: "blah", expand: true}, {Item: "2", expand: false}]';
$.cookie('sidebar', sidebarstate );
...

var sidebar = $.cookie('sidebar');
alert('sidebar: ' + sidebar);
Community
  • 1
  • 1
Simon C
  • 9,008
  • 3
  • 33
  • 53