One of the challenges of building Ajax-enabled applications it that you often lose the functionality of the browser’s back and forward buttons.
jHash is a solid attempt to mitigate that problem. Check it out.
jHash is a JavaScript library that allows developers to manage the location.hash value on the client-side similarly to how we manage query string variables on the server-side.
It’s built in such a way that it gracefully degrades for older browsers, too.
Given a URL with query string parameters, say, https://churchm.ag/jhash-for-maintaining-browser-history#comments?page=2, you would leverage jHash like this:
[cc lang=”javascript”]
// get root hash value
// this returns ‘comments’
var root = jHash.root();
// get query value
// this will return 3
var page = jHash.val(“page”);
// set root hash value
jHash.root(“postTitle”);
// set query value
jHash.val(“page”, 4);
[/cc]
Incredibly useful. Love the implementation of this.
Chris Pietschmann says
Thanks! I’m glad you like jHash!
Tom says
Totally, Chris. Nice work!