处理IFRAMES时,后退按钮不起作用

时间:2010-07-19 14:09:16

标签: javascript html http

我有一个包含带有src到第1页的IFRAME的页面然后我在父页面上创建了一个按钮,用于将IFRAME源切换到第2页。 在Chrome上,当我点击后退按钮时,它会将我引导到父页面的历史记录页面,而不是仅仅将IFRAME内容重定向回第1页。

有没有人见过这种行为?它有什么问题吗?

Thx

1 个答案:

答案 0 :(得分:1)

我使用的一个简单解决方案是将父框架的location.hash设置为子iframe的URL(或其他唯一ID)。

当用户按下后退按钮location.hash将改变。

然后以下观察者将更新您的框架(更改URL时需要关闭)

var currentHash= window.location.hash, myiFrame = document.getElementById('myiFrame');
window.setInterval(function () {
         if (window.location.hash != currentHash){
             currentHash = window.location.hash;
             myiFrame.src = currentHash
         }
    },250);