Jump to content

editing a youtube embed code with xml


Guest MWSO

Recommended Posts

I have a website where i am trying to make my xml file add the youtube video code to the embed for many different videos. instead of having to copy and paste the embed several times. My first failed attempt went like this:if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); }else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }xmlhttp.open("GET","videos.xml",false);xmlhttp.send();xmlDoc=xmlhttp.responseXML; var x=xmlDoc.getElementsByTagName("video");for (i=0;i<x.length;i++) { document.write("[first part of youtube embed code]"); document.write(x.getElementsByTagName("identity")[0].childNodes[0].nodeValue); document.write("[second part of youtube embed code]"); document.write(x.getElementsByTagName("identity")[0].childNodes[0].nodeValue); document.write("[last part of youtube embed code]"); }but this didn't work!i need a javascript code that i can use to plug in the necessary data to the code from my XML file.I'm wondering if something similar to this will work: (note: this code i know doesn't work, because i just guessed on it)var youtubeEmbed = "<object width='640' height='385'><param name='movie' value='http://www.youtube.com/watch?v=";var VideoId = document.write(x.getElementsByTagName("identity")[0].childNodes[0].nodeValue);var MidEmbed = "&hl=en_US&fs=1&rel=0&color1=0x5d1719&color2=0xcd311b'></param><param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param><embed src='http://www.youtube.com/watch?v="var EndEmbed = "&hl=en_US&fs=1&rel=0&color1=0x5d1719&color2=0xcd311b' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width='640' height='385'></embed></object>"document.write(youtubeEmbed + VideoId + MidEmbed + VideoId + EndEmbed)please help me!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...