views:

573

answers:

2

Hello, I'd like to use the anchor part of the url (after the #) so that my page can have ajax/dhtml but still be able to have bookmarks work properly. I'm wondering is someone can help me get started on writing some javascript code for this. I'm using jQuery, but if the solution's a generic one, that's fine too.

For my page, I could have settings like: "a" could be a number from 10-50 "b" is a 0 or 1 "c" is a 0 or 1 etc...

I'd like some tips on writing optimized javascript code which could both parse and set something like #a=23&b=0&c=1

Also, I'd like to keep my url as short as possible, so if the default of "a" was 23, in the example above, the a=23 would be omitted.

Is there a library that does all this stuff already?

+4  A: 

Have a look at the jQuery history plugin: http://www.mikage.to/jquery/jquery_history.html

J-P
+2  A: 

I'm develoing a slightly better history module which automatically converts the hash information to a native JavaScript object. It is event driven, which means it fires the assigned event(s) when the hash is changed. Although Firefox keeps the "hash history" IE does not so you need a workaround by using a hidden iframe which holds the hash information.

You can have a look at the source here: http://jslib-test.amplio-vita.net/JSLib/js/aV.main.history.js

The "queryString to Object converter" function is in the file http://jslib-test.amplio-vita.net/JSLib/js/aV.ext.object.js under the name of "Object.fromQueryString".

Feel free to ask more information if you need.

BYK