iframe set value on input outside js

Solutions on MaxInterview for iframe set value on input outside js by the best coders in the world

showing results for - "iframe set value on input outside js"
Helga
21 May 2016
1<body>
2    <iframe id="site2-frame" src="http://www.mysite2.com/index.php"></iframe>
3</body>
4
Sara
12 May 2019
1<body>
2    <input id="input-field" />
3</body>
4
Malak
27 Mar 2020
1var frame = document.getElementById('site2-frame');
2
3frame.contentWindow.postMessage('Something something something', '*');
4
Miranda
29 Apr 2017
1var input = document.getElementById('input-field');
2
3window.addEventListener('message', function(e) {
4    // Check the origin, accept messages only if they are from YOUR site!
5    if (/^http\:\/\/www\.mysite1\.com/.test(e.origin)) {
6        input.value = e.data; 
7        // This will be 'Something something something'
8    }
9});
10