-1

how to get youtube video id via javascript can anyone help me

here is the youtube http://www.youtube.com/watch?v=mG6DRzIyhOo

Yu Hao
  • 111,229
  • 40
  • 211
  • 267

1 Answers1

0

For your simple case; use the = javascript String.substr function :

var url = "http://www.youtube.com/watch?v=mG6DRzIyhOo";
var video_id = url.substr(url.indexOf("=")+1);

But since youtube can have a variety of different video url formats, I would recommend using the following solution using regular expressions : https://stackoverflow.com/a/8260383/3303171

Community
  • 1
  • 1
mujtaba_ahmad
  • 372
  • 3
  • 12