<script async src = "https://platform.twitter.com/widgets.js" charset = "utf-8"></script>
const container = document.querySelector ("# container");
const clickHandler = (event) =>{
  alert ("clicked");
container.addEventListener ("click", clickHandler, true);
  • jsfiddle

Like the sample above, I want to execute JavaScript processing when I click the embedded tweet on Twitter.
The handler registered in the click event does not work.

addEventListenerThe third argument oftrueI tried it, but the result was the same.

ActualiframeSince the page loaded inside will be an embedded widget of Twitter,

  1. iframeInsidewindow windowAgainstclickUnable to set event
  2. iframeThe implementation that prevents the click event of the DOM element inside will not solve it.

If i have any idea how to operate the event handler under such conditions and why the event handler does not work, please teach me. Thank you.

  • Answer # 1

    Unless Twitter has such an API, there is nothing you can do in the browser.

    Event bubblingSame documentBecause it happens only inside