Skip to content

Instantly share code, notes, and snippets.

@ArvinH
Last active July 26, 2016 09:12
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 ArvinH/4e08ab26a94c0047f32c905d20aee6e0 to your computer and use it in GitHub Desktop.
Save ArvinH/4e08ab26a94c0047f32c905d20aee6e0 to your computer and use it in GitHub Desktop.
// fork from https://gist.github.com/takien/4077195
function YouTubeGetID(url){
var ID = '';
url = url.replace(/(>|<)/gi,'').split(/(vi\/|v=|\/v\/|youtu\.be\/|\/embed\/)/);
if(url[2] !== undefined) {
ID = url[2].split(/[^0-9a-z_\-]/i);
ID = ID[0];
}
else {
ID = url.toString();
}
return ID;
}
var url = 'http://youtube.googleapis.com/v/4e_kz79tjb8?version=3';
url1 = 'https://www.youtube.com/watch?feature=g-vrec&v=Y1xs_xPb46M';
url2 = 'http://www.youtube.com/watch?feature=player_embedded&v=Ab25nviakcw#';
url3 = 'http://youtu.be/Ab25nviakcw';
url4 = 'http://www.youtube.com/watch?v=Ab25nviakcw';
url5 = '<iframe width="420" height="315" src="http://www.youtube.com/embed/Ab25nviakcw" frameborder="0" allowfullscreen></iframe>';
url6 = '<object width="420" height="315"><param name="movie" value="http://www.youtube-nocookie.com/v/Ab25nviakcw?version=3&amp;hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube-nocookie.com/v/Ab25nviakcw?version=3&amp;hl=en_US" type="application/x-shockwave-flash" width="420" height="315" allowscriptaccess="always" allowfullscreen="true"></embed></object>';
url7 = 'http://i1.ytimg.com/vi/Ab25nviakcw/default.jpg';
url8 = 'https://www.youtube.com/watch?v=BGL22PTIOAM&feature=g-all-xit';
url9 = 'BGL22PTIOAM';
document.querySelector(".youtubeId").innerHTML = YouTubeGetID(url);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment