Possible Ways to Communicate Between iFrame and Pa

2019-01-25 17:52发布

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.

4条回答
Lonely孤独者°
2楼-- · 2019-01-25 18:16

No success because you cannot for security reasons.

查看更多
乱世女痞
3楼-- · 2019-01-25 18:21

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/

查看更多
何必那么认真
4楼-- · 2019-01-25 18:28

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.

查看更多
乱世女痞
5楼-- · 2019-01-25 18:35

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.

查看更多
登录 后发表回答