I want to send a message to the parent window like this:
window.parent.postMessage({type: 'gg', data: '0'}, '*');
But the parent window isn't receiving anything in the useEffect:
useEffect(() => {
const handleMessage = (event: MessageEvent) => {
console.log("fsfsfs");
if (event.data.type === 'toolInfo') {
const receivedValue = event.data.value;
console.log(receivedValue); // This will log 'someValue'
// Do something with the received value
}
};
window.addEventListener('message', handleMessage);
return () => {
window.removeEventListener('message', handleMessage);
};
}, []);
it is not printing anything. Right now I'm testing at localhost, so the iframe has 127.0.0.1:9001 and the parent has 127.0.0.1:3000.