Answer the question
In order to leave comments, you need to log in
Getting an error when using Youtube API?
Hello!
I ran into a problem - when using the Youtube API, an error pops up on the video:
Here is the code that I used:
export default class VideoPlayer {
constructor(triggers, overlay) {
this.btns = document.querySelectorAll(triggers);
this.overlay = document.querySelector(overlay);
this.close = this.overlay.querySelector('.close');
}
createPlayer(url) {
this.player = new YT.Player('frame', {
height: '100%',
width: '100%',
videoId: `${url}`,
});
console.log(this.player);
this.overlay.style.display = 'flex';
}
init() {
const tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
const firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
this.btns.forEach(btn => {
btn.addEventListener('click', () => {
const path = btn.getAttribute('data-url');
this.createPlayer();
});
});
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question