internet-explorer - window.history.back() 在 iframe 中重新加载 Internet Explorer 中的页面?

标签 internet-explorer iframe back browser-history

当我的页面位于 iframe 中时,我注意到 Internet Explorer 的一种奇怪行为。似乎 iframe 在调用 window.history.back() 时会自行重新加载,即使只有 URL 中的哈希值应该改变。当页面不在 iframe 中时,它会正常运行并且不会重新加载页面。知道为什么会发生这种情况以及如何预防吗?

我创建了一个 fiddle ,将在 IE9 中演示这一点:

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

jsfiddle 使用 iframe,因此行为将是 iframe 行为。单击“#foo”和“#bar”将更改 URL 中的哈希值。现在单击“返回”链接将触发 window.history.back()。请注意,当您这样做时时间戳会发生变化,表明页面正在重新加载。

或者,如果您直接加载 iframe:

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

您会注意到单击“返回”时时间戳不会改变。

这只是一个 IE 问题,因为无论是否在 iframe 内,Chrome 和 Firefox 都是一致的。

知道如何防止这种重新加载吗?

最佳答案

好吧,当我从上下文菜单中选择后退命令时,它也是如此。在 IE10 中,您可以使用 HTML5 State Management .恐怕在 IE9 中您必须跟踪哈希历史,然后像这样更改它:

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

编辑

那这个呢?
当您调用 javascript:window.top.location.hash='bar' ,你可以抓到onhashchange父窗口中的事件,然后调用 scrollTo在 iframe 中。但这仅适用于同一域。

关于internet-explorer - window.history.back() 在 iframe 中重新加载 Internet Explorer 中的页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11040768/

相关文章:

javascript - IE8 和 z-index CSS 属性的奇怪问题

html - Internet Explorer 仅显示背景

java - Android:在不启动新 Activity 的情况下添加后退按钮

javascript - 跟踪链接到我的 iframe/widget 的 URL

javascript - 使用 iframe 或 lightbox 在我的页面顶部堆叠另一个页面

iOS/swift : How to implement longPressed action for backButton?

java - 如何在具有抽屉式导航和 Web View 的应用程序中启用返回上一页

IE 中类似元素的 CSS

internet-explorer - VBA/VB 脚本自动网页抓取循环/IE 登录

javascript - 使用 jquery 设置内部 iframe 内 div 的宽度 *无需* iframe 上有 id