Skip to content

Instantly share code, notes, and snippets.

@simofacc
Last active October 25, 2017 07:49
Show Gist options
  • Save simofacc/3cfbc68c1e1507923d71 to your computer and use it in GitHub Desktop.
Save simofacc/3cfbc68c1e1507923d71 to your computer and use it in GitHub Desktop.
How to stop a youtube iframe video after closing a popup
//Cache jQuery object in a variable
var $youtubeIframeId = $('#YourIFrameID');
//First get the iframe URL
var url = $youtubeIframeId.attr('src');
//Then assign the src to an empty String, this then stops the video from playing
$youtubeIframeId.attr('src', '');
// Finally reassign the iframe URL (url) back to the iframe, so when you hide the video and show it again you still have the correct source
$youtubeIframeId.attr('src', url);
@simofacc
Copy link
Author

Updated the code with proper caching of the jQuery object and fixing the comments grammar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment