<object id="idVideo" name="idVideo" width="90%" height="70%" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">
<param name="movie" value="http://www.youtube.com/watch?v=gCAcU3p9GNo&hl=en_US&fs=1&rel=0&hd=1&border=0&enablejsapi=1"/>';
<param name="allowFullScreen" value="true"/>';
<param name="allowScriptAccess" value="always"/>';
<param name="wmode" value="transparent"/>';
<embed src="http://www.youtube.com/watch?v=gCAcU3p9GNo&hl=en_US&fs=1&rel=0&hd=1&border=0&enablejsapi=1" type="application/x-shockwave-flash" allowScriptAccess="always" allowfullscreen="true" width="100%" id="idVideoPlayer" name="idVideoPlayer" wmode="transparent" height="80%"/>
</object>';
//get the handle to Video object with id 'idVideo'
var videoObj = document.getElementById("idVideo");
//get the handle to the array of param elements
var params = videoObj.getElementsByTagName("param");
//iterate through the param elements
for ( var counter = 0; counter < params.length; counter++ )
{
var param = params [ counter ];
//if the param name is 'movie', then set the 'value' attribute to the youtube video URL you want to dynamically set
if ( param.getAttribute( "name" ) == "movie" )
{
param.setAttribute( "value", "http://www.youtube.com/watch?v=gCAcU3p9GNo&hl=en_US&fs=1&rel=0&hd=1&border=0&enablejsapi=1" );
}
}
//finally set the same youtube video URL to the embed object with id 'idVideoPlayer'
document.getElementById( "idVideoPlayer" ).setAttribute( "src", "http://www.youtube.com/watch?v=gCAcU3p9GNo&hl=en_US&fs=1&rel=0&hd=1&border=0&enablejsapi=1" );
$( "#idVideo param[name='movie']" ).attr("value", "http://www.youtube.com/watch?v=gCAcU3p9GNo&hl=en_US&fs=1&rel=0&hd=1&border=0&enablejsapi=1");
$( "#idVideoPlayer" ).attr( "src", "http://www.youtube.com/watch?v=gCAcU3p9GNo&hl=en_US&fs=1&rel=0&hd=1&border=0&enablejsapi=1");
var videoURL = "http://www.youtube.com/embed/gCAcU3p9GNo";
var videohtml = '<iframe width="96%" height="75%" src="' + videoURL + '" class="youtube-player" frameborder="0"></iframe>';
//iframe-video-container is the id of the element in which iframe will be set
$("#iframe-video-container").html(videohtml);
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)