Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
126
rated 0 times [  132] [ 6]  / answers: 1 / hits: 28234  / 11 Years ago, fri, august 9, 2013, 12:00:00

I'm trying to load YouTube's iframe API. So far, all I'm trying to do is make and load the player. It seems to load the API, but then not recognize YT.Player() as a constructor. The exact error I'm getting at that line, in the chrome js console, is:



    Uncaught TypeError: undefined is not a function 


So... What in the world am I doing wrong? I've thrown console.log statements all over this thing, and tried rewriting it in a few ways. I've tried copying the api into a local file. I've tried loading it with regular script tags. I've tried loading it with the wacky DOM Modification they used in the api reference at https://developers.google.com/youtube/iframe_api_reference. I'm pretty sure the code below should work:



    function youtubeAPIReady(script, textStatus, jqXHR)
{
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: 'CxTtN0dCDaY'
});
}

function readyFunction()
{
$.getScript(https://www.youtube.com/iframe_api, youtubeAPIReady);
}

jQuery(document).ready(readyFunction);


Any help?


More From » jquery

 Answers
43

Quote from http://api.jquery.com/jQuery.getScript/




The callback is fired once the script has been loaded but not
necessarily executed.




The API probably hasn't run by the time you call YT.Player()


[#76443] Wednesday, August 7, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tatyanna

Total Points: 552
Total Questions: 96
Total Answers: 96

Location: Cook Islands
Member since Thu, May 21, 2020
4 Years ago
;