This is my iframe:
#htmlDiv {
position: absolute;
top: 0px;
left: 300px;
height: 650px;
width: 1130px;
}
#htmlFrame {
position: absolute;
top: 0px;
left: 0px;
margin: 10px 10px 10px 10px;
padding: 0px 0px 0px 0px;
height: 630px;
width: 1110px;
}
<div id="htmlDiv">
<iframe id="htmlFrame"></iframe>
</div>
$('#htmlFrame').click(function(){
alert('clicked');
});
But when I click inside the iframe, it doesn't show "clicked".
How do I detect click inside iframe.
I did this:
Your current code is working fine, try to click it to the border of the
iframe
and the alert will show. I tried to create a solution for you by adding an overlay to theiframe
You can see the DEMO
You cannot detect a click event on an
iframe
. What can be done is you can place aoverlapping layer
on top of youriframe
and capture the click event of the overlapping div. See below snippet: