我刚刚注意到我的针对 iFrame 的 JavaScript 历史记录控件正在影响父级。代码是:
document.getElementById('iframeid').contentWindow.history.back(-1);
document.getElementById('iframeid').contentWindow.history.forward(-1);
它工作正常,直到 iframe 中没有任何东西可以后退或前进,然后它将影响父框架向后和向前移动,这种情况发生在所有主要浏览器,safari,opera,chrome,firefox,即 6 7 8。
有人知道如何阻止它吗?
最佳答案
首先检查history
对象的length
:
if (document.getElementById('iframeid').contentWindow.history.length)
{
// your code....
}
仅当 history
对象可以导航时,条件才会运行。
关于针对影响父级的 iFrame 的 JavaScript 历史控制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3328584/