At this point we have a photogallery which uses hashvalues to determine which picture is currently showed to the user, and to support sending the page to a friend and such. Something like:
http://url/photos/#photo-4
When we have loaded the corresponding picture after clicking the next or previous button, we change the url according to the JS 1.1 specification using:
top.location.replace(url.url + hash);
Our wanted behaviour is that no history item is being created, so users can use the back button to leave the photogallery, instead of using the back button to see the previous pictures.
In IE and Firefox the method works like a charm, but Safari and Chrome do make a history item for the changed url. I have found alot of samples how to create history items when using the hash for navigating like this, but I want to do this the other way. Any clue?
The replace() method of the Location interface replaces the current resource 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.
Window location. The replace() method replaces the current document with a new one.
This works as expected now:
On Safari [5.1.7] location.replace() works as expected – the URL is replaced, nothing is added to the back button's queue, and nothing is added to the history menu.
On Chrome [21.0.1180.82] location.replace() is a little tricky – the URL is replaced and nothing is added to the back button's queue, but it does add an item to the history menu.
What makes this tricky is that there are two distinct history queues – the history menu and the back/forward buttons. Click and hold on the back and forward buttons to see their queue and compare with the history menu.
And the history queue of the back/forward buttons is tied to the active tab. Also, the button history remains even when you clear the history menu – at least until you close the tab.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With