Skip to content

Instantly share code, notes, and snippets.

@aaryadev
Created July 3, 2019 05:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaryadev/c60fb662b0c99052770c7184e517d469 to your computer and use it in GitHub Desktop.
Save aaryadev/c60fb662b0c99052770c7184e517d469 to your computer and use it in GitHub Desktop.
function getId(url) {
var regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/;
var match = url.match(regExp);
if (match && match[2].length == 11) {
return match[2];
} else {
return 'error';
}
}
var videoId = getId('http://www.youtube.com/watch?v=zbYf5_S7oJo');
var iframeMarkup = '<iframe width="560" height="315" src="//www.youtube.com/embed/'
+ videoId + '" frameborder="0" allowfullscreen></iframe>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment