【问题标题】:How can I reload the contents of iframe on Windows Metro Style App如何在 Windows Metro Style App 上重新加载 iframe 的内容
【发布时间】:2012-09-25 14:30:30
【问题描述】:

我想要“重新加载”按钮并在单击 Windows Metro Style App 时重新加载 iframe 的内容。 当我单击该按钮时,出现 Javascript 运行时错误,并表示没有写入权限。

源码如下:

== default.html ==

<iframe id="iframe" src="http://example.com" width="800px" height="400px"></iframe>
<button id="reloadButton">Reload</button>

== default.js ==

var reloadButton = document.getElementById("reloadButton");
reloadButton.addEventListener("click", reload, false);

function reload() {
    var iframe = document.getElementById("iframe");
    iframe.contentWindow.location.reload();
}

感谢任何帮助。

谢谢,

【问题讨论】:

    标签: javascript windows-8 microsoft-metro


    【解决方案1】:

    这是因为same origin policy

    你应该这样写:

    iframe.contentWindow.location.href = "http://www.example.com"`
    

    要更新框架内页面的 URL,例如,您可以将其 postMessage 更新为框架的父级 - 如果您有权访问页面的源代码

    【讨论】:

    • 感谢您的建议。使用 postMessage,我可以从父窗口上的按钮刷新 iframe 中的页面。我把示例代码放在 Gist 上:gist.github.com/3792928
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多