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..
Asked
Active
Viewed 1.8k times
8

Rahul
- 364
- 3
- 8
- 21
-
`` 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 May 24 '12 at 10:34
-
May be these will help you http://stackoverflow.com/questions/1508442/jquery-finding-an-element-within-iframe-by-its-text-and-adding-click-function http://stackoverflow.com/questions/205087/jquery-ready-in-a-dynamically-inserted-iframe – Ankur Verma May 24 '12 at 10:40
-
Sorry guys i forgot to mention, both are in different domain. – Rahul May 24 '12 at 10:45
2 Answers
8
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
}

Matthias Ehinger
- 81
- 2
1
Just use parent
from within the iframe once the form is submitted.
parent.document.getElementById('xx').innerHTML = "hello world";

Ja͢ck
- 170,779
- 38
- 263
- 309
-
the iframe location form and from where i am calling are in different domain... can you make me understand a bit more.. – Rahul May 24 '12 at 10:57