最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how to get the response of Iframe submitting a form? - Stack Overflow

programmeradmin3浏览0评论

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

Share Improve this question asked May 24, 2012 at 10:24 RahulRahul 3623 gold badges8 silver badges21 bronze badges 3
  • <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
Add a ment  | 

2 Answers 2

Reset to default 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
}

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

parent.document.getElementById('xx').innerHTML = "hello world";
发布评论

评论列表(0)

  1. 暂无评论