views:

49

answers:

2

I'm looking for a way to update the url in the status bar.. I have a gallery, and when you click your way through the gallery I want the image ID to show up in the URL, so that the user can link directly to the image..

I've read about using hash and so. but as far as I've tried it, that "ruins" the history. If I click the back-button in my browser the previous image would be shown.

Is it possible to add or update a URL parameter, without ruining the history?

Thanks in advance

+3  A: 

Use location.replace to replace the current location:

Replace the current document with the one at the provided URL. The difference from the assign() method is that after using replace() the current page will not be saved in session history, meaning the user won't be able to use the Back button to navigate to it.

Gumbo
Hum, I tried that, but it reloaded the page, and I don't want that either.. XD Thanks anyway (:
guzh
@guzh: You can only change the URI fragment without reloading.
Gumbo
hum, okey. I found out I'd use hash instead, it's easier (: Thanks for your help, I'll look into your solution a bit further!
guzh
+1  A: 

Do it simply this way, when switching to images, add a hash to the url, for example:

location+='#image-'+image_id

your location will become

http://example.org/images/#image-3

instead of the initial

http://example.org/images/

and onload, check if location.hash is not empty, and matches with ^image-(\d+)$ (regular expression pattern), if it matches, do the usual thing you'd have done if a user clicks on image with id (\d+).

To preserve history, use reallysimplehistory.

aularon
Thanks! I figured it was possible for the gallery to show the ID and show the right picture when typing in the picture ID. I'm using Jquery Cycle, and it's a thread over at the jquery forum about this: http://forum.jquery.com/topic/jquery-cycle-plugin-trying-to-achieve-permalinks-while-using-paging - I'll check out the reallysimplehistory-library! Thanks! ;D
guzh