zumpoof
asked on
How can I dynamically add a YouTube movie to a page via dom on IE6+?
I'd like to have an input field where a YouTube id can be entered. This value would then be used to dynamically show the movie on the same page.
I can get it to work on FireFox, but not on IE6 and up.
I'd basically want it to work like this:
1) Enter any YouTube movie id in to form field
2) Press "Load Movie" input button
3) Corresponding YouTube movie appears on page.
Here's the static YouTube HTML for reference:
<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/RSI5wPgCMCs"></param><param name="wmode" value="transparent"></para m><embed src="http://www.youtube.com/v/RSI5wPgCMCs" type="application/x-shockw ave-flash" wmode="transparent" width="425" height="350"></embed></obj ect>
Thanks!
I can get it to work on FireFox, but not on IE6 and up.
I'd basically want it to work like this:
1) Enter any YouTube movie id in to form field
2) Press "Load Movie" input button
3) Corresponding YouTube movie appears on page.
Here's the static YouTube HTML for reference:
<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/RSI5wPgCMCs"></param><param name="wmode" value="transparent"></para
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
basicinstinct,
I can't thank you enough for this; it works perfectly.
Thanks!
Zumpoof
I can't thank you enough for this; it works perfectly.
Thanks!
Zumpoof
my pleasure
<html>
<head>
<script type="text/javascript">
function loadIt(txt)
{
var baseURL = "http://www.youtube.com/v/";
var movie = txt.value;
var useObjs = useObjects();
if(movie.length > 0)
{
movie = baseURL + movie;
var player = document.getElementById('p
var kids = player.childNodes;
for(var i=0; i<kids.length; i++)
{
if(kids[i].nodeType ==1)
{
player.removeChild(kids[i]
}
}
var newPlayer = (useObjs)?buildObject(movi
player.appendChild(newPlay
}
}
function useObjects()
{
var objs = document.getElementsByTagN
if(objs.length > 0)
return true;
else
return false;
}
function buildObject(movie)
{
var obj = document.createElement('ob
var embd = buildEmbed(movie);
var pMovie = buildParam('movie',movie);
var pWmode = buildParam('wmode','transp
obj.appendChild(embd);
obj.appendChild(pMovie);
obj.appendChild(pWmode);
obj.width = 425;
obj.height = 350;
return obj;
}
function buildEmbed(movie)
{
var embd = document.createElement('em
embd.src = movie;
embd.type = "application/x-shockwave-f
embd.wmode = "transparent";
embd.width = 425;
embd.height = 350;
return embd;
}
function buildParam(nm, val)
{
var obj = document.createElement('pa
obj.name = nm;
obj.value = val;
return obj;
}
</script>
</head>
<body>
<form name="foo">
<input type="text" name="mooVid"/><br/>
<input type="button" value="Load Movie" onclick="loadIt(this.form.
</form>
<div id="player">
<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/RSI5wPgCMCs"></param><param name="wmode" value="transparent"></para
</div>
</body>
</html>