【问题标题】:Is it possible to change iframe src using javascript exists in page inside that iframe?是否可以使用 iframe 内的页面中存在的 javascript 更改 iframe src?
【发布时间】:2010-06-16 23:35:58
【问题描述】:

当此 iframe 内容发生更改时,我想更改 iframe 源,iframe 与父页面位于不同的域中。这个能不能做?

我只需要向这个 iframe src 添加一个哈希,这样我就可以从父页面访问这个哈希值并根据这个值做一些事情。

我做了什么:
在 iframe 页面中,我写道:window.location.hash = "close_child";
在父页面中我写道:if (document.getElementById("MyIFrameId").src.indexOf("#close_child") > 0) { 但我总是发现 src 是空的

【问题讨论】:

    标签: javascript html iframe cross-domain


    【解决方案1】:

    我不是 100% 确定,但我认为您应该能够毫无问题地做到这一点。由于 iframe 只是一个框架,因此您应该能够从 iframe 内的代码中更改 location 属性(与其他任何内容相同),并且无论何时进行更改,父页面都应该可见。

    【讨论】:

      【解决方案2】:

      是的,可以做到。父对象无法查看 iFrame,但 IFrame 可以从在 iFrame 中执行 的代码调用 JavaScript 过程,向其传递参数,例如您的哈希值。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-06-26
        • 2012-12-04
        • 2011-02-17
        • 2011-04-13
        • 2014-05-02
        • 2017-08-28
        • 2014-07-17
        • 2013-06-05
        相关资源
        最近更新 更多