使用iframe交叉数据交换

时间:2014-12-18 21:16:10

标签: javascript c# jquery asp.net iframe

我在aspx页面中使用iframe。

  1. Page1.aspx有下拉列表和按钮。我将把按钮点击事件中的下拉列表选定值传递给Page2.aspx iframe1。
  2. 2.在Page2.aspx中我有2个iframe。 iframe1从page1.aspx获取参数并且具有 控件和按钮。在iframe1的按钮单击事件中,我想将iframe1的值传递给iframe2。

    3.如果我更改iframe1中的控件值并单击iframe1中的按钮,iframe2应该刷新。

    请提出任何建议。

1 个答案:

答案 0 :(得分:1)

您可以使用postMessage将信息传递给iframe:

1)在你的接收器中只添加一个监听器:

window.addEventListener("message", receiveMessage, false);

function receiveMessage(event)
{
  if (event.origin !== "http://example.org:8080")
    return;

  // ...
}

2)然后在你的发件人

dstIframe.postMessage("Your message", "https://host.com");

您必须在发送邮件的主机中使用give in参数,如果主机是您要从中接收信息的主机,请检查接收方。