我在 Firefox 和 Internet Explorer 中使用 postMessage
时遇到了问题,而 Google Chrome 每次都工作正常。
我想做的是使用 postMessage
从 iFrame 到我的父级,并执行 closeForm
操作。 iFrame URL 是父域的子域,iFrame 源本身也有 document.domain = document.domain
我相信它应该已经解决了我的问题。
当前 iFrame JavaScript 正在调用 window.top.postMessage('closeForm', '*')
正如我所提到的,这在 Chrome 中很有效,但在 Firefox 中我得到 ReferenceError: window is undefined
所以我将 window.top
更改为 parent.postMessage
但只有在 parent is not Defined< 时我才得到同样的结果
.
同样的事情在 IE9 中也不起作用。有什么建议吗?
最佳答案
您在使用 postmessage
时似乎遇到了问题。您可以使用 jQuery postMessage
。这是我在一些 iframe 跨域问题中使用的方法,并且有效。这是一个例子。
关于JavaScript iFrame 到父级 postMessage 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12348788/