Last active
October 25, 2017 07:49
-
-
Save simofacc/3cfbc68c1e1507923d71 to your computer and use it in GitHub Desktop.
How to stop a youtube iframe video after closing a popup
This file contains 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
//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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated the code with proper caching of the jQuery object and fixing the comments grammar