iFrame 和父页面之间跨域通信的可能方法
请建议从 iFrame 触发父页面事件的可能技术。我尝试了 url Hashing 和使用 window.postMessage 技术,但没有成功。
Please suggest possible techniques to trigger events in parent page from an iFrame. I tried out url Hashing and using window.postMessage techniques but without any success.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
easyXDM 正是为此目的而设计的。
您可以在 http://easyxdm.net 找到它,它有很多示例。
总而言之,它允许两个窗口使用字符串或 RPC 调用“自由”地进行通信。
请参阅http://consumer.easyxdm.net/current/example/methods.html 用于 RPC 演示之一。
easyXDM is designed for this exact purpose.
You can find it at http://easyxdm.net and it has quite a few examples.
To sum it up, it allows two windows to communicate 'freely' using either strings or RPC calls.
See http://consumer.easyxdm.net/current/example/methods.html for one of the RPC-demos.
没有成功,因为出于安全原因你不能成功。
No success because you cannot for security reasons.
这个问题的现代答案是新的跨文档消息传递(Web Messaging API)
请参阅此处的 Opera 介绍:
http://dev.opera.com/articles/view/window-postmessage-messagechannel/
或此处的规范:http://www.w3.org/TR/webmessaging/
The modern answer to this question is the new cross-document messaging (Web Messaging API)
See Opera's introduction here:
http://dev.opera.com/articles/view/window-postmessage-messagechannel/
Or the specification here: http://www.w3.org/TR/webmessaging/
我想到的唯一想法是在服务器端有一个脚本,iFrame 将其事件发送到该脚本(与唯一 ID 结合),并且父页面可以轮询(通过其域上的服务器脚本或 JSONP)。不过,这需要做很多工作,并且需要父页面和 iframe 的配合。
The only idea that comes to mind is to have a script on server side that the iFrame sends its events to (combined with a unique ID) and that the parent page can poll (either through a server script on its domain, or JSONP). That's a lot of work to do, though, and requires cooperation from both the parent page and the iframe.