How do I postMessage to a sibling iFrame

后端 未结 2 1481
伪装坚强ぢ
伪装坚强ぢ 2020-12-20 03:44

I\'m looking for a way to postMessage to a sibling iFrame without any javascript in the parent page. The difficulty I\'m having is trying to get the window object for the ot

2条回答
  •  感动是毒
    2020-12-20 04:03

    You will not be able to do this as an iframe cannot interact with the page it's emedded within (nor anything within that page), unless the parent is under the same domain (which, in your example, it is not). If it could, it would pose XSS security issues as you indicated that you're aware of.

    Instead, you could:

    • Set a cookie in /a/ and poll for it in /b/ (this is going to be expensive though as /b/ would have to somehow keep making calls to the server)
    • Use a 'HTML5' persistent data storage mechanism, storing the data from /a/ and poll for it in /b/ (perhaps localStorage could be used)
    • Use a websocket to link all of your siblings via the server
    • Reconsider what you're trying to do: it sounds very odd what you're trying to achieve - are you sure there isn't a better way of doing things than using iframes like this?

提交回复
热议问题