onclick in an iframe

0

Good afternoon!

Well I'm trying to byclick to make the banner disappear when I click on it, but I'm not getting it! My code:

 <div id="mime">
      <iframe style="border:none; overflow:hidden; width:605px; height:250px; float:left;" frameborder="0" scrolling="No" src="http://migre.me/pWQGp"></iframe></div><script>vardiv=document.getElementById('mime');div.style.display='none';//Mostraadivapós1minutosetTimeout(function(){div.style.display='block';},60000);</script>

I'vetried:

<divid="mime">
        <iframe style="border:none; overflow:hidden; width:605px; height:250px; float:left;" frameborder="0" scrolling="No" src="http://migre.me/pWQGp"onClick="OcultarDiv();" style="cursor: pointer;"></iframe>
    </div>
<script>
var div = document.getElementById('mime');
div.style.display = 'none';

// Mostra a div após 1 minuto
setTimeout(function () {
    div.style.display = 'block';
}, 1);

 function OcultarDiv(){  // função ocultar
    div.style.display = "none";
 }
</script>

I've tried several other codes, but I have no results! Please help me ! (I'm a beginner in javascript, I know almost nothing, but I'm learning!)

    
asked by anonymous 07.06.2015 / 18:50

1 answer

1

The iFrame even though it is on your page is an external element, and onclick does not work as expected. Events triggered on this page belong to it and can not be manipulated outside theA. Most of the exception is if the iFrame is in the same domain.

But if you want to know when the iFrame was clicked you can use this idea:

creates a new div that has the same position and dimensions as the div that has the iFrame. It gives position: absolute; and z-index greater than iFrame to get it to be on top of the other. There you can hide events about this div and you do not notice it.

Note that in this case the user can not click on the banner ad, and this is not very correct for the advertiser ...

var frameDiv = document.getElementById('mime');
var filterDiv = document.getElementById('filtro');
filterDiv.style.zIndex = 100;
filterDiv.addEventListener('click', function () {
    frameDiv.style.display = 'none';
});

jsFiddle: link

    
07.06.2015 / 18:56