1677 posts Envato Elite Author
  • Has referred 10+ members
  • Has sold $125,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+6 more
Tean says

If I create a youtube iframe with jquery and append it to the dom like so:

var videoIFrame = $('<iframe>', {
frameborder: 0,
src: 'http://www.youtube.com/embed/u1zgFlCw8Aw?enablejsapi=1',
width: 400+'px',
height: 300+'px'
});</iframe>

I get a youtube video but how do I access youtube api from this?

5351 posts The Dude Abides
  • Located in United States
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $125,000+ on Envato Market
  • Has been part of the Envato Community for over 5 years
+9 more
CodingJack says

I’ve only used the jsapi once, but I think you have to add an id to the end of your src string like this:

http://www.youtube.com/e/VIDEO_ID?enablejsapi=1&version=3&playerapiid=ytplayer

Then catching the reference to the player:

function onYouTubePlayerReady(playerId)  {

      ytplayer = document.getElementById("myytplayer");

}

But the problem with this is that the video is loaded in an iframe and communicating becomes tricky. I haven’t tried this before but here’s a possible solution:

http://stackoverflow.com/questions/251420/invoking-javascript-in-iframe-from-parent-page
1677 posts Envato Elite Author
  • Has referred 10+ members
  • Has sold $125,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+6 more
Tean says

Not sure why the syntax is so different from Vimeo iframe api.

For Vimeo after you create iframe the same way as above, you get the player reference like so:

vimeoPlayer = Froogaloop(videoIFrame[0]);

and thats it, you just listen for ‘ready’ event and you can use it.

But for youtube it goes like this:

http://apiblog.youtube.com/2011/01/introducing-javascript-player-api-for.html

I am not sure if this event onYouTubePlayerReady is going to be heard from jQuery.

5490 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Located in Australia
  • Has sold $1,000+ on Envato Market
+4 more
Australia says

Contact my mate nirvana tikku.

Via http://www.tikku.com/

He is a YouTube genius.

1677 posts Envato Elite Author
  • Has referred 10+ members
  • Has sold $125,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+6 more
Tean says

Thanks, I saw this TubePlayer plugin before, but I wanted to use the simplest of embeds.

5490 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Located in Australia
  • Has sold $1,000+ on Envato Market
+4 more
Australia says
Tean said
Thanks, I saw this TubePlayer plugin before, but I wanted to use the simplest of embeds.

He is so helpful, just ask him.

by
by
by
by
by
by