I’ve setup a page with a number of categories and a filter system. However, I’d like users to be able to enter anchors into the URL so that they can simply visit, for example:
http://www.site.com/page#categoryA
To see simply Category A
This functions quite well, but doesn’t allow for multiple anchors. The only solution I’ve come up with is to keep tacking on the visible categories to the anchor and process the string with jQuery, or is there a better way to do this?
It is also important that when a user clicks beyond this page, hitting the back button presents the categories in their previously chosen visible/invisible states.
This should be possible via hash changes similar to your current approach.
A good way of doing this could look something like this: http://www.site.com/page/#CategoryA,CategoryB,CategoryC,etc
Or, if you need to use named parameters, you could even do: http://www.site.com/page/#categories:CategoryA,CategoryB,CategoryC/tags:TagA,TagB,TagC,etc
The jQuery hashchange plugin can handle cross-browser hashchanges for you. A function call to your own code with some basic string parsing / regex checking should take care of the rest and create a nice object from which to read the passed-in values.