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

0

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Hum, I tried that, but it reloaded the page, and I don't want that either.. XD Thanks anyway (:
@guzh: You can only change the URI fragment without reloading.
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!
1

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.

1 Comment

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: forum.jquery.com/topic/… - I'll check out the reallysimplehistory-library! Thanks! ;D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.