<div id="ytburl">https://www.youtube.com/watch?v=vW8SLCiZQMA</div>
<div id="youtube"></div>
<script>
function getYouTubeVideoImage(url, size) {
if (url === null) {
return '';
}
size = (size === null) ? 'big' : size;
var vid;
var results;
if (url.indexOf('watch?v=') != -1) {
results = url.replace('https://www.youtube.com/watch?v=', '');
vid = results;
} else if (url.indexOf('youtu.be') != -1) {
results = url.replace('https://youtu.be/', '');
vid = results;
}
if (size == 'small') {
return 'http://img.youtube.com/vi/' + vid + '/2.jpg';
} else {
return 'http://img.youtube.com/vi/' + vid + '/0.jpg';
}
}
$('#youtube').append('<img src="' + getYouTubeVideoImage('https://youtu.be/vW8SLCiZQMA') + '"/>');
$('#youtube').append('<img src="' + getYouTubeVideoImage('https://www.youtube.com/watch?v=vW8SLCiZQMA', 'small') + '"/>');
</script>
Smoga bisa dikembangkan lagi sesuai dengan kebutuhan Anda..
ConversionConversion EmoticonEmoticon