Skip to content

Instantly share code, notes, and snippets.

@jnicol
Forked from cferdinandi/stop-video.js
Last active February 26, 2023 07:13
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 jnicol/3d7b10a9fd5ec46028f36bd27a4ff68d to your computer and use it in GitHub Desktop.
Save jnicol/3d7b10a9fd5ec46028f36bd27a4ff68d to your computer and use it in GitHub Desktop.
A simple method to stop YouTube, Vimeo, and HTML5 videos from playing.
/**
* Stop all iframes or HTML5 <video>'s from playing
*/
var stopVideos = function () {
var videos = document.querySelectorAll('iframe, video');
Array.prototype.forEach.call(videos, function (video) {
if (video.tagName.toLowerCase() === 'video') {
video.pause();
} else {
var src = video.src;
video.src = src;
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment