Skip to content

Instantly share code, notes, and snippets.

@alexfraundorf-com
Forked from cferdinandi/stop-video.js
Created May 21, 2017 00:32
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 alexfraundorf-com/15c47d88a1c08ef05ce535f750de4105 to your computer and use it in GitHub Desktop.
Save alexfraundorf-com/15c47d88a1c08ef05ce535f750de4105 to your computer and use it in GitHub Desktop.
A simple method to stop YouTube, Vimeo, and HTML5 videos from playing.
/**
* Stop an iframe or HTML5 <video> from playing
* @param {Element} element The element that contains the video
*/
var stopVideo = function ( element ) {
var iframe = element.querySelector( 'iframe');
var video = element.querySelector( 'video' );
if ( iframe ) {
var iframeSrc = iframe.src;
iframe.src = iframeSrc;
}
if ( video ) {
video.pause();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment