最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Communicating cross-origin from parent to child iframe - Stack Overflow

programmeradmin1浏览0评论

I'm working through Third Party Javascript. I'm particularly interested in communication between a parent page and a child frame from a different origin. Using window.postMessage, it's trivial to safely send messages from the child and have the parent receive them with the message event.

I have had no luck going the other direction. Can I get some confirmation that it is not possible to communicate from the parent to the child using postMessage? If not what are ways of working around this problem?

I'm working through Third Party Javascript. I'm particularly interested in communication between a parent page and a child frame from a different origin. Using window.postMessage, it's trivial to safely send messages from the child and have the parent receive them with the message event.

I have had no luck going the other direction. Can I get some confirmation that it is not possible to communicate from the parent to the child using postMessage? If not what are ways of working around this problem?

Share Improve this question asked Sep 25, 2013 at 17:46 Ben JacobsBen Jacobs 2,5264 gold badges25 silver badges34 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 16

You should be able to use .postMessage() between any two cooperating windows. It doesn't matter which direction you are sending the message. If it is not working in one direction, then there is probably an error in the implementation. You may need to make sure you have the proper window object.

For an iframe, you would want to use the .contentWindow property to get its window in modern browsers.

Some good documentation here: https://developer.mozilla.org/en-US/docs/Web/API/window.postMessage

发布评论

评论列表(0)

  1. 暂无评论