Closed sonoman closed 7 years ago
There's no built-in way to do this right now, because it's not always possible to enumerate all of the open popups and iframes, but if you just want to message all iframes it's a pretty simple traversal.
function messageAllFrames(win, name) {
postRobot.send(win, name);
for (var i = 0; i < win.frames.length; i++) {
messageAllFrames(win.frames[i], name);
}
}
messageAllFrames(window.top, 'foo');
Does that work for your use-case?
It totally makes sense. Thank you!
I tested your suggestion with a blank page with 2 iframes, and it worked. But when I combine with xComponent, it won't work... is there any incompatibility to use post-robot with xComponent alltogether ?
Do you see a specific error when doing this in conjunction with xcomponent?
Actually, I'm not receiving anything on the event listener application, and the callback that I have on the "send", is returning an error related to cross origin...I have the parent application running on localhost:4200 (where I have the "Send" call), and is rendering an xcomponent with an application on localhost:8080 (where I have the "on" listener). The following is a stringify of the event object returned on the callback
ack: "error"
domain:"http://localhost:4200"
error:"Blocked a frame with origin "http://localhost:8080" from accessing a cross-origin frame.↵Error: Blocked a frame with origin "http://localhost:8080" from accessing a cross-origin frame.↵ at JSON.stringify (
Looks like http://localhost:8080/?uid=8c123d7ab7&version=latest&xcomponent=1:79:49
is some code running in your iframe, guessing in a script tag? Could you share the code?
I need to send to all xcomponents running within a parent window a certain message (like broadcasting)....
Can post-robot handle this requirement in any way I'm not seeing ?