Jump to content

Auto-Play mp4 Every Time Modal Window Is Opened


beau

Recommended Posts

I have an mp4 video in a modal window, and the video auto-plays when the first time the modal window is opened.
My HTML is:
<video controls autoplay>
<source src="filename.mp4" type="video/mp4">

But if the user closes the modal window then re-opens it, the mp4 doesn't auto play, you have to click the "Play" button
button_play.png

What code can be added to cause it to always auto-play?

Link to comment
Share on other sites

You can have Javascript play the video when the modal opens. The simplest way is to give an ID to your video element.

<video id="my-video" controls autoplay>

In the function that opens the modal window add this line:

document.getElementById("my-video").play();
Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...