Window.history.back () reloads page in Internet Explorer when inside iframe?

I notice strange behavior with Internet Explorer when my page is inside an iframe. It seems that the iframe is being reloaded when window.history.back () is called, although only the hash in the url should change. When the page is not inside the iframe, it behaves correctly and does not reload the page. Any idea why this is happening and how to prevent it?

I created a script that will demonstrate this in IE9:

http://jsfiddle.net/peh96/5/

jsfiddle uses an iframe, so the behavior will be iframe behavior. Pressing "#foo" and "#bar" will change the hash in the URL. Now clicking on the BACK link will call window.history.back (). Note that the timestamp changes when you do this, indicating that the page is reloading.

Alternatively, if you load the iframe directly:

http://fiddle.jshell.net/peh96/5/show/

You will notice that the time stamp does not change when you press "BACK".

This is a problem only with IE, since Chrome and Firefox are compatible with inside the iframe or not.

Any idea how to prevent this reboot?

+6
source share
1 answer

Well, when I select the Back command from the context menu, it does the same. In IE10, you can use HTML5 State Management . I am afraid that in IE9 you should keep track of the hash history and modify it like this:

document.getElementById('back').addEventListener('click', function () { window.location.hash = 'abc'; }, false); 

Edit

What about this one? When you call javascript:window.top.location.hash='bar' , you can catch the onhashchange event in the parent window and then call scrollTo in the iframe. But this only works in the same domain.

+2
source

Source: https://habr.com/ru/post/918128/


All Articles