Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

top.location.replace creates history item in Safari/Chrome

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?

like image 916
Jan Jongboom Avatar asked Jul 31 '09 13:07

Jan Jongboom


People also ask

Why is the location replace () method preferred over the location assign () method?

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.

What does Window location replace do?

Window location. The replace() method replaces the current document with a new one.


1 Answers

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.

like image 153
sirch Avatar answered Sep 28 '22 20:09

sirch