【问题标题】:window.parent in iframe from one subdomain to anotheriframe 中的 window.parent 从一个子域到另一个子域
【发布时间】:2014-05-18 20:39:19
【问题描述】:

我有一个页面,其中包含一个 iFrame,而 iFrame 又包含一个表单。提交此表单后,我需要将某些信息返回给家长。

这是我试图用来实现此目的的代码示例...

window.parent.$('#imagename').val("<?php echo $imagename; ?>");

问题是页面在 sub1.domain.com 上,而表单(在 iframe 中)在 sub2.domain.com 上

我拥有这两个子域的所有权,所以我可以做些什么来完成这项工作?

【问题讨论】:

    标签: javascript php jquery iframe window.parent


    【解决方案1】:

    您可以使用 document.domain='yourdomain.com 在父页面和 iFrame 中设置域。 这将使您可以毫无问题地从父级到 iframe 进行通信,反之亦然。浏览器会将它们视为同一个域

    参见 MDN 文档:https://developer.mozilla.org/en-US/docs/Web/API/document.domain

    【讨论】:

      猜你喜欢
      • 2013-07-04
      • 2015-01-05
      • 2019-01-12
      • 2013-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-29
      相关资源
      最近更新 更多