Skip to content

Instantly share code, notes, and snippets.

@krasimir
Created February 3, 2014 18:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krasimir/8789934 to your computer and use it in GitHub Desktop.
Save krasimir/8789934 to your computer and use it in GitHub Desktop.
Convert YouTube link to an iframe
var filterTextArea = function(text) {
text = text.replace(/(<([^>]+)>)/ig, '');
var re = /(?:https?:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=)?([\w\-]{10,12})(?:&feature)?(?:[\w\-]{0})?/g;
var iframe = '<iframe width="640" height="360" src="http://www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe>';
text = iframe.replace('$1', text.split(re)[1]);
return text;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment