简体   繁体   中英

fill iframe input field from click on parent

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?

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','*');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM