Skip to content

Instantly share code, notes, and snippets.

@stephencarr
Last active December 25, 2015 03:29
Show Gist options
  • Save stephencarr/6910043 to your computer and use it in GitHub Desktop.
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
/**
* 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