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?
Asked
Active
Viewed 195 times
0
-
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
-
1Please 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 Answers
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,267
- 1
- 19
- 32