-
-
Save jnicol/3d7b10a9fd5ec46028f36bd27a4ff68d to your computer and use it in GitHub Desktop.
A simple method to stop YouTube, Vimeo, and HTML5 videos from playing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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