从同一文档的下一个iframe中引用iframe

时间:2011-07-12 11:28:21

标签: iframe same-origin-policy postmessage

我有来自同一个域的两个iframe( iframe1 iframe2 ),这些iframe托管在来自不同域的文档中。如何从 iframe2 中引用 iframe1 ,以便他们可以通过 postMessage()进行通信。

2 个答案:

答案 0 :(得分:1)

我将自己回答,postMessage()非常适合iframe与其父文档之间的通信。但在我的情况下,最好使用sessionStorage进行来自同一来源的iframe之间的通信。

https://developer.mozilla.org/en/DOM/Storage

答案 1 :(得分:0)

HTML5 postMessage方法的使用说明和示例非常well documented。如果您使用的是jQuery,您可能还会发现following plugin非常有用,因为它抽象了大量必要的代码。

相关问题