Wil Wells
Wil Wells

Reputation: 205

When Adding Dynamic YouTube Objects The Parameters Are Not Working (JavaScript)

When I add the YouTube players to my page, the 'rel' and 'end' parameters are not working. Everything else about the player works fun except these to parameters:

function onYouTubeIframeAPIReady() {
    $.each($(".ytiFrame"),function(index){
        ytPlayers[String($(this).attr("id"))] = new YT.Player(String($(this).attr("id")),{
            events: {
              'onStateChange': onPlayerStateChange
            },
            videoId: $(this).data('video'),
            'rel':0,
            'end':3
        });
    })
}

As you can see, I'm adding the new YT.Player dynamically and the video embeds in the iFrame perfectly and plays just fine, and the event 'onStateChange' fires perfectly too. But the 'rel' and 'end' parameters are not working at all.

I've also tried:

            rel:0,
            end:3

and:

            rel:'0',
            end:'3'

and:

            'rel':'0',
            'end':'3'

none made a difference and were ignored. In fact, when I look at the mark-up in debug, the iFrame doesn't even have these parameters listed.

Upvotes: 0

Views: 216

Answers (1)

Wil Wells
Wil Wells

Reputation: 205

Duplicate question here: Adding additional parameters to the yt.player object from youtube

Answer is to use this to add parameters:

playerVars: { 'rel': 0, 'end': 3 }

Upvotes: 0

Related Questions