【问题标题】:how to get the response of Iframe submitting a form?如何获得 Iframe 提交表单的响应?
【发布时间】:2012-05-24 10:24:57
【问题描述】:

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

【问题讨论】:

标签: javascript jquery forms iframe response


【解决方案1】:

您可以使用 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
}

【讨论】:

    【解决方案2】:

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

    parent.document.getElementById('xx').innerHTML = "hello world";
    

    【讨论】:

    • iframe 位置表格和我打电话的地方在不同的域中......你能让我了解更多......
    猜你喜欢
    • 2011-03-11
    • 2017-05-10
    • 2015-05-15
    • 2013-10-13
    • 2015-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-29
    相关资源
    最近更新 更多