0
Q:

iframe set value on input outside js

var input = document.getElementById('input-field');

window.addEventListener('message', function(e) {
    // Check the origin, accept messages only if they are from YOUR site!
    if (/^http\:\/\/www\.mysite1\.com/.test(e.origin)) {
        input.value = e.data; 
        // This will be 'Something something something'
    }
});
0
<body>
    <input id="input-field" />
</body>
0
<body>
    <iframe id="site2-frame" src="http://www.mysite2.com/index.php"></iframe>
</body>
0
var frame = document.getElementById('site2-frame');

frame.contentWindow.postMessage('Something something something', '*');
0

New to Communities?

Join the community