Detect clicks inside a sourceful Iframe for mobile

237 views Asked by At

enter image description here

I have a situation here.

  1. I am inside a sourceful Iframe(id=a-sourceful-one) AND NOT on the main page
  2. My code is executing in a script (id=this-is-my-executing-script)
  3. I have to track clicks inside another sourceful iframe (id=track-clicks-within-this-frame-for-mobiles)
  4. I am in mobile mode

Basically, I'm in mobile mode and inside a sourceful Iframe. I want to track clicks within another sourceful Iframe whose Iframe element is accessable to me.

Is there a way to achieve this?

1

There are 1 answers

0
Christoffer Törnroos On

I'm pretty sure that you can't catch events inside an iframe DOM unless you're on the same domain. You can however catch a event when clicking the actual iframe if you wrap the iframe inside a div and set the CSS property pointer-events: none to the iframe element.

Something like this

<div id="wrapper">
   <iframe></iframe>
</div>
iframe {
   pointer-events: none;
}
$('.wrapper').on('click', function(e) {
     // do sth here
   });