I have to load react js app in iframe and parent application is sending data to iframe react app using below code:
const myiframe = document.getElementById('myIframe');
myiframe.contentWindow.postMessage('message', '*');
<iframe id='myIframe' name="my-iframe" src="http://localhost:3000" ></iframe>
In iframe app I am trying to receive data:
useEffect(() => {
window.onmessage = function (event) {
console.log('event received')
}
}, []);
But window.onmessage never triggers or triggers intermittently.
I checked by keeping window.onmessage out of useEffect but it is not working.
Has anyone faced this issue? Need help.
Thanks.