【问题标题】:javascript get iframe url's current page on subdomainjavascript获取子域上的iframe url当前页面
【发布时间】:2015-09-10 12:27:15
【问题描述】:

我需要获取页面上 iframe 所在的页面 url,因为我们使用 iframe 来处理订购产品。但是,对于我的生活,我似乎无法让它显示 iframe 的 URL(显示是一个测试,因为当我看到它有效时它会自动发送电子邮件)

代码:

<button onClick="myFunction()">Test</button>
<script>
function myFunction() {
alert(document.getElementById("iFrame").documentWindow.location.href);
}
</script> 
<iframe src="https://iframe.mydomain.co.uk" id="iFrame" width="98%" height="100%"></iframe>

此代码正在https://products.mydomain.co.uk 上使用。 正如我所说,警报只是在那里,所以我只需按下按钮即可看到它显示新域,以便我可以执行其余部分所需的操作。

有什么想法吗?

【问题讨论】:

  • 尝试 document.getElementById("iframe_id").contentWindow.location.href
  • 不,这也不行:/
  • iframe 和主页是否在同一个域中?
  • 主域相同,子域不同

标签: javascript html iframe


【解决方案1】:

在两个页面中添加 document.domain = 'your.domain'。

像这样。不要忘记parent.top

document.domain = 'corp.local';

只有父母喜欢

document.domain = '公司';

不会工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-24
    • 1970-01-01
    • 2012-11-12
    • 1970-01-01
    • 2012-12-04
    • 2011-06-17
    • 2014-11-21
    相关资源
    最近更新 更多