Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get the response of Iframe submitting a form?

I have a form that has been called using a iframe, now when that form is submitted i want to catch a response in the main site from where the iframe was called and depending on it would enable/disable a button in main page.
Please anyone help me out..

like image 422
Rahul Avatar asked May 24 '12 10:05

Rahul


2 Answers

You could use window.postMessage API. Its is a HTML5 feature and not all browsers support this feature

In the Iframe and Parent Site you need a check if the browser does support postMessage

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

you can send your message with

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

In your Parent (Main Site) you need an eventlistener

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

function receive(evt)
{
  // handles the event
}
like image 59
Matthias Ehinger Avatar answered Sep 19 '22 15:09

Matthias Ehinger


Just use parent from within the iframe once the form is submitted.

parent.document.getElementById('xx').innerHTML = "hello world";
like image 33
Ja͢ck Avatar answered Sep 17 '22 15:09

Ja͢ck