How to get an Iframe response representing a form?

I have a form that was called using iframe, now that this form has been submitted, I want to catch the answer on the main site from where the iframe was called, and depending on it, will enable / disable the button on the main page.
Please help me.

+3
source share
2 answers

You can use the window.postMessage API. Its function is HTML5, and not all browsers support this function.

On the IFrame and the parent site you need to check if the browser supports postMessage

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

you can send a message using

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

In your parent (main site) you need an eventlistener

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

function receive(evt)
{
  // handles the event
}
+3
source

parent iframe .

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

All Articles