0

I'm tring to detect a click on a iframe element, I have been searching for an anser, but I cant find any anser. In the following code, you can see that the button works, with the oneclick(), but the iframe doesn't.

<iframe onclick="starttime()" src="https://player.vimeo.com/video/527719365" width="50%" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>
<button onclick="starttime()">Agenda tu llamada</button>
<p id="demo" style="visibility:hidden;">Hello World</p>

<script>
    function starttime(){
      document.getElementById("demo").style.visibility = 'visible';
    }
</script>
  • This answers could be helpful: https://stackoverflow.com/q/15080222/383904 PS don't use `on*` attributes, same as you hopefully don't use `style` attributes. JS should be all inside your `script`. Use addEventListener() instead. – Roko C. Buljan Mar 23 '21 at 09:42

1 Answers1

0

You can use the addEventListener as an event handler. In the following way: iframe.document.addEventListener('click', function(event) {clic(this.id);}, false);

However, I recommend that you use a better approach to access your frame (I can only assume that you are using the DOM0 way of accessing frame windows by their name - something that is only kept around for backward compatibility):

document.getElementById("myFrame").contentDocument.addEventListener(...);

Math Geek
  • 1
  • 1