Execute a JavaScript when a video has started to play: - Javascript DOM Event

Javascript examples for DOM Event:onplay

Description

Execute a JavaScript when a video has started to play:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p>Press play.</p>

<video controls onplay="myFunction()">
  <source src="your.mp4" type="video/mp4">
  <source src="your.ogg" type="video/ogg">
  Your browser does not support HTML5 video.
</video>/*from  ww  w .j ava 2  s.c  o m*/

<script>
function myFunction() {
    console.log("The video has started to play");
}
</script>

</body>
</html>

Related Tutorials