6

我有一个使用 iframe 调用的表单,现在当提交该表单时,我想在主站点中捕获调用 iframe 的响应,并根据它启用/禁用主页中的按钮。
请任何人帮助我..

4

2 回答 2

7

您可以使用 window.postMessage API。它是 HTML5 功能,并非所有浏览器都支持此功能

在 iframe 和父站点中,您需要检查浏览器是否支持 postMessage

if (typeof window.postMessage != 'undefined') { }

你可以发送你的消息

window.parent.postMessage("test","*");

在您的父母(主站点)中,您需要一个事件监听器

window.addEventListener('message', receive, false);

function receive(evt)
{
  // handles the event
}
于 2012-05-24T12:30:32.210 回答
1

提交表单后,只需parent在 iframe 中使用即可。

parent.document.getElementById('xx').innerHTML = "hello world";
于 2012-05-24T10:37:26.167 回答