【发布时间】:2021-11-15 01:08:51
【问题描述】:
任何建议如何使 iframe 与父窗口通信。 场景:
在 Iframe 内部,同一域中的单独网站具有多个链接。 当用户点击 iframe 内的链接时,该值应传播到父窗口。
我尝试跟踪 iframe 中的点击事件并获取 iFrame.src 但它没有 工作。
HTML:
<iframe #Iframe class="iframek" (click)="onChange(kIframe)" sandbox="allow-same-origin allow-scripts allow-top-navigation" id="iframe_k" [src]='safeUrl' scrolling="auto" frameborder="0" allowfullscreen=true wmode="transparent" name="kiframe"></iframe>
onChange(iframe) {
console.log("onchange");
if(iframe.contentWindow)
{
console.log(iframe.contentWindow.document);
}
else{
console.log(iframe.contentWindow);
}
console.log(iframe.getAttribute('src'));
}
【问题讨论】:
-
看看这个答案:stackoverflow.com/a/16657480/4633925 对于相同的域 iframe,您不需要发布消息。您可以访问 iframe,反之亦然。
标签: javascript iframe angular10