You can save state using:
- URL hash: mysite.com#a=1,b=2 ...or however you want to record your state.
- Cookies
- Window.name
On reload, check for the recorded state, parse it and re-execute it in your code.
Edit:
When you execute something that changes in the UI you need to record this action somewhere (i.e. Panel A is open), in some sort of code. It could be name, value pairs (ID,STATE|ID,STATE..etc) in a string or whatever you choose. You then need to program a mechanism that takes this "saved state" information and re-initializes the UI back to where it was.
Once you've accomplished a way to represent and re-initialize the state, you have to consider how you'll save and retrieve it.
You can save it is a cookie, if it's not too big. When the page loads, check for the cookie and parse the data and run your re-initialization routine to restore the UI.
Another persistent place to stash data is in window.name
, which can hold a string of up to 2mb. Same deal as a cookie.
The third method is to store the state information in the URL: document.location = document.location + "#" + stateData
. You can then parse what's in the URL to grab your state data.
The "url/hash" method is becoming the preferred technique as it allows bookmarking and is a new specification to allow search-bots to read ajax-based sites easily.
See: http://code.google.com/intl/sv-SE/web/ajaxcrawling/docs/specification.html