How to access event "onplay()" for iframe?

Member

by mac , in category: Javascript , 8 months ago

How to access event "onplay()" for iframe?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by tressie.damore , 8 months ago

@mac 

To access the "onplay()" event for an iframe, you can add an event listener to the iframe element in your HTML document. Here is an example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
<iframe id="myFrame" src="https://example.com"></iframe>

<script>
const iframe = document.getElementById('myFrame');

iframe.addEventListener('play', function() {
  // Your code here for what should happen when the iframe starts playing
  console.log('Iframe is now playing');
});
</script>


In this example, when the iframe starts playing, the play event is triggered and the event listener attached to the iframe element will run the specified code. You can replace the console.log statement with any other code you want to run when the iframe starts playing.

Related Threads:

How to access onfocus event from iframe (cross-origin)?
How to access to iframe inside iframe?
How to call unload event of iframe?
How to add an event listener to an iframe?
How to attach click event on iframe?
How to capture click event with jquery for iframe?