Jump to content

Javascript object changing


amiller112

Recommended Posts

Hi, I am attempting to use a javascript function to change the elements in an object.I'm not sure if its possible, but I want to be able to click a button that changes a youtube.com video to another, using the DOM.A sort of youtube video viewer, I can view the initial video even if I use a javascript function to generate the HTML, however I can't seem to get my head round how to update it so it shows another.Thanks.

Link to comment
Share on other sites

I'll try and get some up later today.Basically I have the object copied from the youtube.com link and have placed that inside a div tag.What I want to do is change the object inside the div tag so it plays another youtube.com video.I have tried document.write (the div id is movie, dont have code infront of me), but might not be using it properly.The other thing I was trying to find was a way to refresh just the div tag contents, or use cookies to store the selected movie and perfrom a page refresh.I might just abandon this approach tho, and just open a new browser window for each video as it is selected.

Link to comment
Share on other sites

Check out the HTML DOM - http://www.w3schools.com/htmldom/default.asp - specifically the innerHTML property. You could use it to change the contents of a div:

<div id="mydiv"></div><script type="text/javascript">var mydiv = document.getElementById("mydiv");mydiv.innerHTML = "This is the new content for the div!";</script>

But using the HTML DOM, you might also simply be able to change the URL for whatever container you are using to display the video(s). Post your code when you have it and someone should be able to help you.

Link to comment
Share on other sites

I have abandoned my original idea for the time being. Instead I am using the code below to open a new window, the window then has it's location changed to the location of the new movie, then I use the focus() function to bring it to the front.

<script language="JavaScript" type="text/javascript">	function videoload(videoloc){	myref=window.open(videoloc,'Red Dwarf','height=350,width=425,	resizable=0,location=0,status=0,menubar=0,copyhistory=0');	myref.focus();	}</script><input type="button" value="Next" name="Next" onClick="videoload('http://www.youtube.com/v/8W89CFS3pU4');"><input type="button" value="other" name="Next" onClick="videoload('http://www.youtube.com/v/VoXBQjTF1LE');">

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...