954,597 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to change the the value of src in <embed> using javascript

need help here. how can i change the src in using javascript that works in firefox?

ex.

<embed src="music.mid">


- how can i change "music.mid" to another midi file.

odee
Light Poster
27 posts since Dec 2004
Reputation Points: 10
Solved Threads: 0
 

First, I don't work much with embeds, so this is speculation. But you need to give your element an ID, as such:

<embed id="myMidi" src="music.mid">



Then, you can get to the object using document.getElementById("myMidi") . At that point, try simply changing the source:

document.getElementById("myMidi").src = "newfile.mid";
tgreer
Made Her Cry
Team Colleague
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37
 


document.getElementById("myMidi").src = "newfile.mid";

Hi, I already use this case but the embed object c'not accept the src.
there is my problem.

hari123
Newbie Poster
1 post since Aug 2006
Reputation Points: 10
Solved Threads: 0
 

The "embed" tag may not allow that. What you may have to do instead is place the tag into a div, and then use JavaScript to completely rewrite the contents of the div. Research ".innerHTML".

tgreer
Made Her Cry
Team Colleague
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37
 

There is a solution:

var oEmbed = document.getElementById("myMidi");
oEmbed.setAttribute("src", "newfile.mid")

Voynex
Newbie Poster
15 posts since Jul 2007
Reputation Points: 6
Solved Threads: 3
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You