【问题标题】:redirect url in iframe to parent window on click点击时将 iframe 中的 url 重定向到父窗口
【发布时间】:2014-05-27 01:11:24
【问题描述】:

我正在使用我正在使用的平台对自动生成的数据进行 iframe,因此我无法直接访问 iframe 链接。所以我想做的是编写一个脚本,在 iframe 中获取linka 值,然后使用link 重定向父页面。

一切都在同一个域上,我只是无法编辑自动生成数据的页面,所以我使用的是 iframe。

这是我正在使用/尝试实现的脚本,但我看不出我做错了什么:

<script>
    function replaceLoad(oIframe) {
        oIframe.onload = function () {
            document.getElementById("replaceLoad").contentWindow.location = "javascript:moveMe()"
        }
    }
</script>

这是 iframe html:

<iframe scrolling="no" src="http://www.discoverhomefinder.com/dljones/homes-for-sale/AZ/Anthem?wmode=opaque" frameborder="0" style="border: 0px none; margin-left: 0px; height: 3900px; margin-top: -12%; width: 100%;" onload="replaceLoad(this)">
</iframe>

【问题讨论】:

  • 我在以下帖子中的回答可能正是您想要的:stackoverflow.com/questions/23858219/… 另外,您不应该在 hrefs 中使用 javascript,这是不好的做法。 :)
  • 您可以通过更改 iframe 的 src 来更新 iframe 的位置。
  • 问题是关于父页面,另外,iframe 没有replaceLoad 的ID,所以它永远找不到它。第三,可以使用window.top.location.href = "url.com"重定向父页面。
  • 如果我无法控制 iframe 中链接的代码,这会起作用吗?它们是在系统上自动生成的。
  • 而且我没有尝试重定向到某个链接我有一个页面上有多个列表,点击任何链接我都需要重定向到链接的src 的父链接

标签: javascript jquery html iframe


【解决方案1】:

据我了解,您只想将父页面重定向到 iframe 的 url, 您可以在您的函数中执行此操作:

function replaceLoad(oIframe) {
    window.location.href = oIframe.src;
}

【讨论】:

    猜你喜欢
    • 2011-02-23
    • 1970-01-01
    • 2012-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-16
    • 1970-01-01
    • 2011-04-01
    相关资源
    最近更新 更多