0

I have an iframe containing a form. On the parent page, I have an interactive div which populates data on mouse clicks (map.) Is there a way where I can fill an input field that is part of the iframe by clicking on something from the parent page?

wa7d
  • 119
  • 1
  • 12
  • Do you have access to the iframe code? Can you add some Javascript to it? – Sergii Vorobei Oct 11 '18 at 09:42
  • @SergiiVorobei yes I do. It’s a form with fields where user inputs some data then clicks upload to upload the file to the server – wa7d Oct 11 '18 at 09:43
  • 1
    Please take a look at this then: https://stackoverflow.com/questions/9153445/how-to-communicate-between-iframe-and-the-parent-site – Sergii Vorobei Oct 11 '18 at 09:44

1 Answers1

1

You can communicate between your page and iFrame content using messages.

// frame.html:
window.onmessage = function(event) {
    // handle message and fill input field
    var text = event.data;
};

// page:
// <iframe id="myframe" src="framed.htm"></iframe>

document.getElementById('myframe').contentWindow.postMessage('textToFill','*');
Przemek Marcinkiewicz
  • 1,141
  • 1
  • 17
  • 29