how to get the response of Iframe submitting a form?

14,614

Solution 1

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
}

Solution 2

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

parent.document.getElementById('xx').innerHTML = "hello world";
Share:
14,614

Related videos on Youtube

Rahul
Author by

Rahul

Updated on September 15, 2022

Comments

  • Rahul
    Rahul over 1 year

    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..

  • Rahul
    Rahul almost 12 years
    the iframe location form and from where i am calling are in different domain... can you make me understand a bit more..