I need to receive data from cross-origin iframe. The Iframe content website is also mine. Everybody says that postMessage() works in both directions, but not for me.
If anybody has some experience about my problem, I'll be very grateful :)
in iframe's website code
window.postMessage("ehooo!", "*");
in website code
<iframe src="https://ehooo.com" name="iframe" onLoad="iframeLoaded()"></iframe>
<script>
function iframeLoaded() {
event.target.contentWindow.addEventListener("message", e => {
console.log(e.data);
});
}
</script>
the console output
Uncaught DOMException: Blocked a frame with origin "https://ehooo.com" from accessing a cross-origin frame.