Voici la fonction pour intégrer la vidéo youtube en html. Dans cet affichage vidéo youtube sur le clic, mais je veux le faire sur le chargement en utilisant javascript. Comment peut-on faire? De l'aide?Comment charger iframe en charge avec jquery?
youtubeLoadVideos : function() {
// Find all the YouTube video embedded on a page
var videos = document.getElementsByClassName("youtube");
for (var i=0; i<videos.length; i++) {
var youtube = videos[i];
// Attach an onclick event to the YouTube Thumbnail
youtube.onclick = function() {
// Create an iFrame with autoplay set to true
var iframe = document.createElement("iframe");
iframe.setAttribute("src", "https://www.youtube.com/embed/" + this.id);
// The height and width of the iFrame should be the same as parent
iframe.style.width = this.style.width;
iframe.style.height = this.style.height;
iframe.style.clear = 'both';
// Replace the YouTube thumbnail with YouTube HTML5 Player
this.parentNode.replaceChild(iframe, this);
};
}
}
Merci pour votre réponse. J'ai plus d'un div donc je veux charger plus d'une vidéos Alors, que peut-on faire dans ce cas? – eegloo
@eegloo: utilisez simplement appendChild (iframe) pour ajouter le div désiré. –
Merci beaucoup. Maintenant ça fonctionne bien. – eegloo