Skip to content

Instantly share code, notes, and snippets.

Last active Dec 23, 2015
What would you like to do?
Create an embedded YouTube player that will load a video
var ytplayersinfolist = [];
//This function creates an <iframe> (and YouTube player)
//after the API code downloads
function onYouTubeIframeAPIReady() {
if (typeof window.playerInfoList === 'undefined')
for (var i = 0; i < window.playerInfoList.length; i++) {
// This function loads the IFrame Player API code asynchronously
function registerYTIFrameApi() {
var tag = document.createElement('script');
tag.src = "";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
function initYTPlayer(playerInfo) {
return new YT.Player(, {
height: playerInfo.height,
width: playerInfo.width,
videoId: playerInfo.videoId
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment