ListenerCode4Parentiframe <iframe src="/other/extra/scripts/fakesocialmedia/lastshorthands.html" id="iframe" width="600" height="100"></iframe> <br><hr> <script> window.addEventListener('message', (event) => { if (event.origin !== window.location.origin) { return; } // If the iframe sends a shorthand selection message... if (event.data.type === 'shorthandSelected') { const textbox = document.getElementById('textbox'); textbox.value += event.data.shorthand + " "; } }); document.getElementById('parentBtn').addEventListener('click', () => { const iframe = document.getElementById('iframe'); iframe.contentWindow.postMessage({ type: 'changeBackgroundColor', color: 'lightgreen' }, '*'); }); </script> <textarea id="textbox" name="textbox" rows="4" cols="50"></textarea>