Solved

DHTML YouTube movie

Posted on 2006-11-28
2
630 Views
Last Modified: 2012-05-05
I'm trying to come up w/ a JavaScript version of the YouTube movie snippet.  My goal is to be able to pass a js function a YouTube id and have the appropriate movie play w/o the page refreshing. For example I'd like to be able to click on one of the links below, and have the DIV's contents load the selected movie.

<A HREF="javascript:showMovie('li5-f7GpYSU');>Show MST3K 1/10</A>
<A HREF="javascript:showMovie('oONMPeqJFYA');>Show MST3K 2/10</A>

<div id="movie_container">No movie selected</div>



for reference, here is the raw YouTube HTML:

<object width="425" height="350">
      <param name="movie" value="http://www.youtube.com/v/li5-f7GpYSU"></param>
      <param name="wmode" value="transparent"></param>
      <embed src="http://www.youtube.com/v/li5-f7GpYSU" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350">
      </embed>
</object>


Thanks!
Zumpoof
0
Comment
Question by:zumpoof
  • 2
2 Comments
 
LVL 12

Accepted Solution

by:
enachemc earned 500 total points
ID: 18026145
you can use document.getElementById("movie_container").innerHTML='<object width="425" height="350">     <param name="movie" value="http://www.youtube.com/v/li5-f7GpYSU"></param>     <param name="wmode" value="transparent"></param>     <embed src="http://www.youtube.com/v/li5-f7GpYSU" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350">     </embed></object>';
//one line above

Or you can dinamicaly create the object and assign the required properties, and then attach this new object as a child of the movie_container object.
0
 
LVL 12

Expert Comment

by:enachemc
ID: 18026167
var obj = document.createElement("object");
obj.width=425;
obj.height=425;
var param = document.createElement("param");
param.name = "movie"
......
obj.insertBefore(param);//this will add the param element to the object element
....
document.getElementById.insertBefore(obj);


0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now