Skip to content

Instantly share code, notes, and snippets.

@MistyBlunch
Forked from cferdinandi/stop-video.js
Created July 4, 2018 15:44
Show Gist options
  • Select an option

  • Save MistyBlunch/9acf44715a4e704e6d5ecd40e25ec4fb to your computer and use it in GitHub Desktop.

Select an option

Save MistyBlunch/9acf44715a4e704e6d5ecd40e25ec4fb 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