Skip to content

Instantly share code, notes, and snippets.

@zehfernandes
Created July 30, 2018 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zehfernandes/8ba4d8159fcf303d4ac0754f6dbde390 to your computer and use it in GitHub Desktop.
Save zehfernandes/8ba4d8159fcf303d4ac0754f6dbde390 to your computer and use it in GitHub Desktop.
videos = document.querySelectorAll('video')
videos.forEach(function(element) {
var promise = element.play();
if (promise !== undefined) {
promise.then(_ => {
// Autoplay started!
}).catch(error => {
element.setAttribute("controls","controls")
});
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment