1

I want to submit a form into an iframe and get the result. The result has to be a text that javascript can understand, so I think that JSON is the best idea.

I know how to get the iframe object on javascript, but I have no ideia on how to get the content. The content of my iframe is only JSON, how can I retrieve it with javascript?

user937450
  • 713
  • 5
  • 11
  • 20
  • similar http://stackoverflow.com/questions/14591039/jquery-submit-into-an-iframe – Musa Mar 28 '13 at 05:46
  • Please refer below URL: http://stackoverflow.com/questions/926916/how-to-get-the-bodys-content-of-an-iframe-in-javascript – web2008 Mar 28 '13 at 05:49
  • @suresh.g I played with this object a little bit without any improvement: document.getElementById("myIframeID").contentDocument – user937450 Mar 28 '13 at 05:53
  • 1
    @web2008 In this question he want's the body of an HTML document, in my case it's just JSON text, theres no "body" tag that you can refer to. – user937450 Mar 28 '13 at 05:54
  • Maybe if I create a blank HTML page and place the JSON in the body tag would be the best idea, do u guys have a better idea? – user937450 Mar 28 '13 at 05:56
  • The browser is going to create a body element regardless if there was a body tag or not. – Musa Mar 28 '13 at 06:11

1 Answers1

2

You can communicate via JavaScript.

The parent window can be reached using the parent property inside the iframe:

From the iframe do

window.parent.SomeFunctionDefinedInTheParent(JSONObject);
TGH
  • 38,769
  • 12
  • 102
  • 135
  • I thought about it and I know it works. But what if I want to call the same iframe from multiple pages? I'll have to define this function in all of them :( – user937450 Mar 28 '13 at 05:51
  • If you have a master page you can define it in an include file that you reference from the master page. Worst case scenario is that you have to include the JS include file on every page if you don't have a master page – TGH Mar 28 '13 at 05:52
  • If you place it on a master page you will get unnecessary javascript in pages where you don't want to load the iframe. – user937450 Mar 28 '13 at 06:02