'How to send postMessage to iframe from parent page

I'm trying to send a message to iframe from the page, but it seems like this message does not received. Code from the page:

let iframe = document.getElementById('myiframe')
iframe.contentWindow.postMessage('message body', window.location.origin)
console.log('message sent')

Code from the iframe:

window.addEventListener('message', function(m){
  console.log(m)
}, false)

So, in the console I see only the first part - 'message sent', what can be the reason of this issue? Site and iframe have different domains



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source