Capture click on div surrounding an iframe

Viewed 14650

How can I capture a click or mousedown event on a div surrounding an iframe. I've tried attaching the function to click event on the div but since the iframe never bubbles the event up to the surrounding div the function is never called. Is there a way I can capture the event on the div and then propagate it to the iframe for default action?

4 Answers

If you land here because you need to track a click on a PayPal button (like me), and you have access to the JavaScript SDK, you can listen to the click by adding the onClick callback in the initialization.

Example:

paypal.Buttons({
  onClick() {
    // here you can track the click 
  }
}).render('#paypal-container');

Link to the docs: https://developer.paypal.com/sdk/js/reference/#link-oninitonclick.

Related