【问题标题】:Javascript: refresh IFrame browser specificJavascript:刷新 IFrame 浏览器特定
【发布时间】:2012-12-22 11:20:54
【问题描述】:

我需要一个解决方案来刷新适用于不同浏览器的 iframe。
你能确认一下,我在互联网上找到的代码是正确的还是给我正确的 javascript?

IE 7 window.document.getElementById('iframeId').contentWindow.location.reload(true);

IE 8 window.document.getElementById('iframeId').contentWindow.location.reload(true);

IE 9 window.document.getElementById('iframeId').contentWindow.location.reload(true);

火狐 12-17
window.document.getElementById('iframeId').src = window.document.getElementById('iframeId').src;

document.getElementById('iframeId').contentWindow.location.reload();

Chrome 现在
???

Safari 和 Opera 会很好,但以上内容很重要。 iframe 可能位于不同的域中。

非常感谢!

【问题讨论】:

  • 嗨,这适用于 IE 版本吗?我尝试使用这里提到的但无法重新加载 iFrame。

标签: javascript internet-explorer firefox iframe browser


【解决方案1】:

在 Chrome 版本 23.0.1271.97 中,我刚刚尝试使用

document.getElementById('iframeId').contentWindow.location.reload()

它有效。 你可以试试:

document.getElementById('iframeId').contentWindow.location.href = document.getElementById('iframeId').contentWindow.location.href

【讨论】:

    【解决方案2】:
    **Try This**
    location.reload();
    

    【讨论】:

    • 虽然此代码可以提供问题的解决方案,但强烈建议您提供有关此代码为何和/或如何回答问题的附加上下文。从长远来看,只有代码的答案通常会变得毫无用处,因为未来遇到类似问题的观众无法理解解决方案背后的原因。
    猜你喜欢
    • 1970-01-01
    • 2018-03-14
    • 2012-12-17
    • 2011-03-15
    • 2012-07-13
    • 1970-01-01
    • 2015-12-17
    • 2014-08-10
    • 1970-01-01
    相关资源
    最近更新 更多