Any suggestion How to make Iframe communicate to parent window. Scenario :
Inside Iframe there is separate website in same domain having multiple links. When user clicks on Link inside iframe the value should propagate to parent window.
I tried tracking the click event inside Iframe and getting iFrame.src but it didnt work.
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'));
}
You should use cross-origin communication between Window objects.
See this answer for details: How to communicate between iframe and the parent site?.
To implement your scenario, do the following: