【问题标题】:change window location when iframe location is changed更改 iframe 位置时更改窗口位置
【发布时间】:2011-03-20 04:23:58
【问题描述】:

有没有办法做到这一点,如果 iframe 内的页面不是 src,那么它会将父页面更改为 iframe 试图去的 url?像这样的:

<script>
function redir() {
    if(document.getElementById("myiframe").src != 'http://www.google.com'){
        window.location = document.getElementById("myiframe").location
    }
}
</script>
<iframe src="http://www.google.com/" id="google" onload="redir()"></iframe>

【问题讨论】:

    标签: url iframe redirect location parent


    【解决方案1】:

    没有。

    根据同源策略,不允许父页面获取有关 iframe 中发生的任何信息,除非页面位于同一域中。

    【讨论】:

      猜你喜欢
      • 2011-10-21
      • 2011-04-09
      • 2021-11-17
      • 2012-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-05
      • 2013-01-05
      相关资源
      最近更新 更多