3

This has been answered in the context of "detect a click inside an iframe".

I don't need to know if a click is inside the iframe, but I'm trying to react to swipe events anywhere on the window for mobile browsers, and some embedded content is interfering with that.

I've tried attaching event handlers to window and document, with no success.

My suspicion is this isn't possible, but if is please let me know.

Wesley
  • 5,381
  • 9
  • 42
  • 65
  • I've seen that, but it seems focused on the distinction of a click inside vs outside the iframe. I want to know if an event has happened, and don't need to distinguish it's origin. – Wesley May 12 '14 at 05:26
  • Try overlaying a div over the iframe with `opacity: 0;`. – nderscore May 12 '14 at 05:33
  • 1
    This might work, but in order to be clickable it would have to have a higher z-index than the iFrame, which seems like it would render the iFrame impossible to interact with. – Wesley May 12 '14 at 05:39
  • this might seem completely crazy but if you can get the x,y,width,height position of the iframe and an x/y position of the mouse you can find out if the click occured inside the area of the iframe -with some basic maths. Now please feel free to insult my eagerness to sell a nuclear bomb when the customer only wanted some fireworks – nicholaswmin May 12 '14 at 05:42
  • This: http://stackoverflow.com/a/3690896/1355315 and this: http://stackoverflow.com/a/3690990/1355315 – Abhitalks May 12 '14 at 05:49
  • @NicholasKyriakides I think this question is not so much about figuring out _where_ the click happened, but _whether_ a click happened at all. If you look at abhitalks' first link, you'll see that's precisely the problem here. – JLRishe May 12 '14 at 05:52
  • @Wesley Yes, putting a div over it would render the iframe impossible to interact with (see the accepted answer in Neel's link). – JLRishe May 12 '14 at 05:57
  • @JLRishe I am getting confused, I though he wanted to register whether the user clicked within the iframe. – nicholaswmin May 12 '14 at 06:24
  • @Wesley maybe if you add some event where on document mousedown/touchstart, the overlay div is removed temporarily, you could still pass click events to the iframe. I haven't tested it though. – nderscore May 12 '14 at 14:27

0 Answers0