Last active
December 25, 2015 03:29
-
-
Save stephencarr/6910043 to your computer and use it in GitHub Desktop.
Quick jQuery function to remove YT videos from the DOM without IE9 freaking out about memory leaks. The problem is detailed here: https://groups.google.com/forum/#!topic/youtube-api-gdata/2JcIaw43dco
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
/** | |
* Safely removes YT player from DOM | |
* @param {object} ytplayer | |
* @param {objext} $wrapper | |
* @return {bool} | |
*/ | |
function cleanYTRemove(ytplayer, $wrapper) { | |
// Do shutdown so IE doesn't freak... | |
if (typeof ytplayer != 'undefined' && typeof ytplayer.div != 'undefined') { | |
// Destroy the Youtube player object | |
ytplayer.destroy(); | |
// Remove src | |
$wrapper.find('iframe').attr('src', 'about:blank'); | |
// Remove container | |
$wrapper.remove(); | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment