views:

37

answers:

2

I'm exploring my options for modifying urls in the browser bar for bookmarking purposes.

Ideally, I'd like to add querystring parameters and cannot determine if this is even possible. I don't want the page to refresh and want to add querystring values on link clicks, ajax calls, etc.

If I can't add querystring parameters, then I'd like to add hash values (http:://someurl.com#hash-value). How should I go about doing this? Should I use plain JavaScript or a framework (jquery, prototype, etc.) and/or framework plugin.

+1  A: 

If you modify the query string, it will refresh. So you should modify window.location.hash.

Matthew Flaschen
+1  A: 

To modify the hash, you can simply do the following in plain JavaScript:

window.location.hash = 'hash-value';

It will add #hash-value to your URL, or will replace it if it already exists, without refreshing the page.

Then to check if a hash value is present, simply do the following:

if (window.location.hash) {
    // Hash is present
    // Use window.location.hash as required
}
else {
    // No hash was set
}
Daniel Vassallo