How to hide a parent element when click to iframe

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/

Upvotes: 1

Views: 285

Answers (1)

Dom Slee
Dom Slee

Reputation: 611

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

Upvotes: 1

Related Questions