1

Why I can't pass events from iframe to parent when are in different domains

window.onload = function () {
    myFrame = document.getElementById('test2');
    myFrame.contentDocument.addEventListener('click', function()
    {
        $("test1").hide();
    });
};
<div id="test1" style="width:150px;height:150px;position:relative;">
    <iframe id="test2" src="http://www.w3schools.com"></iframe>
</div>

I want something like this: http://jsfiddle.net/nqTnz/15/

I try the same code with different domains and doesn't works: http://jsfiddle.net/z6tco5rg/

  • 4
    For [security reason](http://stackoverflow.com/questions/7289139/why-are-iframes-considered-dangerous-and-a-security-risk) – Alexis N-o Jul 16 '15 at 04:02
  • 1
    Same Origin Policy Restrictions prevents it – Arun P Johny Jul 16 '15 at 04:16
  • possible duplicate of [capture click on div surrounding an iframe](http://stackoverflow.com/questions/3690812/capture-click-on-div-surrounding-an-iframe) – stdob-- Jul 16 '15 at 06:06

1 Answers1

1

Not sure if relevant, but have a read of this link:

http://www.codeproject.com/Tips/585663/Communication-with-Cross-Domain-IFrame-A-Cross-Bro

Dom Slee
  • 611
  • 1
  • 5
  • 10