Reputation: 1
I am trying to insert a Youtube video on my website using these code:
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('ytplayer', {
height: '450',
width: '800',
videoId: 'myvideoID',
});
};
But where I am supposed to set rel=0 to do not have suggestions when the video had finished ?
Upvotes: 0
Views: 550
Reputation: 1687
It is an attribute on the player object. Simply add it as a new line. Other things like autoplay, modestBranding, etc. will follow the same style.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('ytplayer', {
height: '450',
width: '800',
videoId: 'myvideoID',
rel: 0
});
};
I've built an app that uses the YouTube Data and Player API, feel free to take what you need: https://github.com/HunterMeyer/YouTV/blob/master/js/scripts.js
Upvotes: 0
Reputation: 19
You should be able to simply append this to the "videoId" so:
player = new YT.Player('ytplayer', { height: '450', width: '800', videoId: 'myvideoID?rel=0', });
Upvotes: 1