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..
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..
-
<iframe src="http://www.example./index.php"></iframe>
Now in this iframe location there is a form, on successful submission of this form, i need to set an event in the page form where it is called. – Rahul Commented May 24, 2012 at 10:34 - May be these will help you stackoverflow./questions/1508442/… stackoverflow./questions/205087/… – Ankur Verma Commented May 24, 2012 at 10:40
- Sorry guys i forgot to mention, both are in different domain. – Rahul Commented May 24, 2012 at 10:45
2 Answers
Reset to default 8You 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
}
Just use parent
from within the iframe once the form is submitted.
parent.document.getElementById('xx').innerHTML = "hello world";