为简化而虚构的情况:
childB.
grandparent页面,其中包含一个显示“父页”的parent。childA和sandbox="allow-scripts"。F 212
parent从grandparent、childA和childB发送和接收消息。
当parent收到消息时,我需要能够识别发送者,但是我找不到正确的方法,因为origin of event是null
function onReceive(message) {
// origin is null when the message comes from a sandboxed frame.
console.log(message.origin);
}你知道一个清楚的方法知道这条信息是谁发来的吗?
发布于 2022-03-21 17:29:06
好吧,比我想象的要简单。实际上,我可以将message.source属性与子iframes的contentWindow进行比较,也可以将其与父级的window.parent进行比较。
https://stackoverflow.com/questions/71532329
复制相似问题