1

This isn't a "how to" question at this stage, more of a "can I."

I am capturing form data on /page1.php - upon submit /page2.php is loaded which contains further form fields that are displayed via an iframe. The form that is loaded is hosted on another server (just in case that makes a difference).

The question I have is; Is there anyway of using javascript (or any other language) to autofill a field that is in the iframe?

I hope that makes sense but if anyone needs any clarification, please let me know.

thanks

  • http://stackoverflow.com/questions/1291812/iframe-javascript-access-parent-dom-across-domains – sfletche Apr 28 '14 at 19:14
  • 1
    "can I" - No :http://stackoverflow.com/questions/364952/jquery-javascript-accessing-contents-of-an-iframe – Steve Apr 28 '14 at 19:15
  • @user574632 You reference a question that was asked/answered 5 years ago!! That's long time and surely new methods are available. – Jonathan Rosenfeld Apr 28 '14 at 19:32
  • @JonathanRosenfeld Same origin policy has not changed. Why are you trying to do this - there is probably a better way, such as php cUrl – Steve Apr 28 '14 at 19:57
  • @user574632 http://www.onlineaspect.com/2010/01/15/backwards-compatible-postmessage/ - To answer your question, I'm trying to pre-populate the form fields in the iframe that are asking for the data I have already collected myself. – Jonathan Rosenfeld Apr 28 '14 at 20:26
  • @JonathanRosenfeld your above link requires you to be able to alter the iframed page to listen for messages. Can you do that? If so it would be easier to just have the iframed page accept GET variables. – Steve Apr 28 '14 at 20:41

1 Answers1

1

This part is important:

The form that is loaded is hosted on another server (just in case that makes a difference).

That makes a big difference, here's why:

"The same-origin policy restricts how a document or script loaded from one origin can interact with a resource from another origin." https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy

You can try to use some Ajax to interact between the pages.

the_marcelo_r
  • 1,847
  • 22
  • 35