N
N
Nikolai Gladky2011-01-12 13:24:25
Opera
Nikolai Gladky, 2011-01-12 13:24:25

JS: Functionality of window.location.replace() for Opera?

In all browsers except Opera, window.location.replace() replaces the url perfectly without making a record in the browser's history (in my case, you need to change the hash, for example "#1").
Is there any way to change the url in opera without making an entry in the browser history?
The bottom line is that there is an image gallery, when switching between images, the hash changes (so that you can give someone a link, and the person got to the same picture that was opened when copying the address). If a visitor wanders through the gallery and clicks "back", then in all browsers, except for opera, he will be taken to the previous page, and in opera to the same page with the previous image. How to avoid it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Keith, 2011-01-12
@daping

Yes, in Opera the window.location.replace method doesn't work as it should. If we change the url with a page reload, then everything is fine. For example:

visit site1.com
go site2.com
javascript: window.location.replace('?q=1')
go back // пользователь на site1.com

But with the hash, such a number was also needed, but I did not find any solution, except through one place:
  • do url hash polling (200ms)
  • fix the transition through the pictures in the gallery
  • if you notice that the URL has changed to the previous one and at the same time we did not fix this change, then the user pressed the back button in the browser
  • we call the history.go(-N) method , where N is the number of transitions through the pictures in the gallery + 1, so the user will be on the page we need.

But I quickly abandoned this decision, settling on polling and just showing the previous picture. This way we save more convenient navigation through the gallery.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question