Here is my code: After the loading, it should invoke event --"onReady", then print out "My player is onReady" in browser console. But it doesn't show. Basically, this is a very simple example for YouTube API usage, but I can't find what's wrong here. Even I have followed steps in the youtube video.
Any helps? Thank you in advance!!
<html>
<head>
<meta charset="UTF-8">
<title>THis is YOutube API testing </title>
</head>
<body>
<iframe id="video" width="560" height="315" src="https://www.youtube.com/embed/02GcUZ6hgzo" frameborder="0" allowfullscreen></iframe>
<script>
//import YouTube API script
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
//create the YouTube Player
var player;
function onYouTubeIframeAPIReady() {
console.log("API is Ready");
player = new YT.Player("video", {
events:{
'onReady': onPlayerReady
}
});
}
function onPlayerReady() {
console.log("My plaer is onReady");
}
</script>
</body>
</html>
Here is log in browser console: