如何从父页
我正在尝试从页面上发送消息到iframe,但似乎没有收到此消息。 页面上的代码:
let iframe = document.getElementById('myiframe')
iframe.contentWindow.postMessage('message body', window.location.origin)
console.log('message sent')
iframe中的代码:
window.addEventListener('message', function(m){
console.log(m)
}, false)
因此,在控制台中,我只看到第一部分 - '消息发送',这个问题的原因是什么?网站和iframe有不同的域
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论