6

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?

Jan Jongboom
  • 24,795
  • 8
  • 74
  • 117

3 Answers3

3

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.

sirch
  • 56
  • 1
3

There seems to be no solution at this point.

Jan Jongboom
  • 24,795
  • 8
  • 74
  • 117
0

Have you looked at assigning your hash using window.location.hash = newHash instead of replacing the entire url?

https://developer.mozilla.org/en/DOM/window.location

Community
  • 1
  • 1
MyItchyChin
  • 12,915
  • 1
  • 21
  • 43
  • Yes "replace(url) 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." And there I got my bug, because that doesn't work in Webkit. – Jan Jongboom Jul 31 '09 at 13:46
  • 1
    location.hash creates history items in all the major browser apart from IE, so that won't work :-) – Jan Jongboom Jul 31 '09 at 14:21