Disable html5 video autoplay

前端 未结 8 1329
感情败类
感情败类 2021-02-02 07:10

How can I disable html5 video autoplay?

what I\'ve tried:

8条回答
  •  长发绾君心
    2021-02-02 07:17

    Indeed setting autoplay to false doesn't help some videos will play anyway. See this case in fiddle.

    You might want to do by code something in the line of if you want to pause all the videos:

    videos = document.querySelectorAll("video"); 
    for(video of videos) {
      video.pause(); 
    }
    

    Of course the above case will not work if the video tag is in a shadow root element, but then hardly any general solution will work with shadow roots elements. There you will need a custom approach and expand first the shadow roots.

提交回复
热议问题