1

I want to click through an iframe but not from Div inside this iframe. So how can I do this?

Like in below Image. I want to capture click in Div but want to skip click through Iframe. So how is this possible?

IFrame Click through and Div Click enabled

I know that

pointer-events:none

is applied for iFrame, But it disable all Iframe's child as well.

VarunJi
  • 685
  • 2
  • 14
  • 31

1 Answers1

0

The following code will help you to do that.

$(document).ready(function() { 
$("#iframe").load(function(){
    var iframe = $('#iframe').contents();
iframe.find("div").click(function(e){ //if you dont have particular ID for div
    alert("The div with id "+e.target.id+" Got clicked");
    if(e.target.id = "expected_div_id") {
        //do something
        alert("i am inside");
    }
});
});
});

Or Do as follow

$(document).ready(function() { 
$("#iframe").load(function(){
    var iframe = $('#iframe').contents();
iframe.find("#div_id").click(function(){ //if you have particular ID for div
    var div_id = $(this).attr('id');
    alert("The div with id "+div_id+" Got clicked");
    if(div_id = "expected_div_id") {
        //do something
        alert("i am doing something here");
    }
});
});
              });
Shridhar
  • 339
  • 2
  • 15
  • Thanks Shridhar, But this is for a div click. What about when I click on Iframe area and then I need Click through feature in it. – VarunJi Mar 02 '15 at 17:00
  • If you click on iframe then also one event have to get trigger? But my above solutions will work for your questions. – Shridhar Mar 02 '15 at 17:03
  • But I don't want any mouse event for Iframe means when i click on Iframe, then Iframe should not care about the mouse event like in "pointer-events:none" feature. – VarunJi Mar 02 '15 at 17:05