我在 aspx 页面中使用 iframe。
- Page1.aspx 有下拉列表和按钮。我将在按钮单击事件中将下拉列表选定的值传递给 Page2.aspx iframe1。
2.在Page2.aspx中我有2个iframe。 iframe1 从 page1.aspx 获取参数,它有 控件和按钮。在iframe1的按钮单击事件中,我想将iframe1的值传递给iframe2。
3.如果我更改 iframe1 中的控件值并单击 iframe1 中的按钮,iframe2 应该会刷新。
请提出任何建议。
最佳答案
您可以使用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");
您必须使用给出参数发送消息的主机,并检查接收者是否是您想要从中接收信息的主机。
关于javascript - 使用iframe进行交叉数据交换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27555846/