Fictional situation for simplification:
grandparent
page containing one parent
iframe displaying the "parent page".childA
and childB
.sandbox="allow-scripts"
for security reasons.parent
sends and receive messages from/to grandparent
, childA
and childB
.
When parent
receives a message, I need to be able to identify the sender, but I can't find the right approach, as the origin
of the event
is null
:
function onReceive(message) {
// origin is null when the message comes from a sandboxed frame.
console.log(message.origin);
}
Do you know a clean way to know who does the message come from?
OK, it was simpler than I expected.
I actually can compare the message.source
property with the contentWindow
of the child iframes
, or window.parent
for the grand parent.