Skip to content

youtube ID 값 추출

MintState March 8, 2017 at 2:39 PM Views 9758

youtube ID 값 추출

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 myId = getId('http://www.youtube.com/watch?v=zbYf5_S7oJo');

var myCode = '<iframe width="560" height="315" src="//www.youtube.com/embed/' 
    + myId + '" frameborder="0" allowfullscreen></iframe>';
Share X Facebook LINE QR code

0 comments

Be the first to comment.