View Full Version : <embed> src

04-30-2007, 05:14 PM

I tried everything possible i knew.
I followed the articles that some people pointed to me.
I was also searching by myself too. I came with nothing so, i am starting agonize.

all i need is to access and change the "src" attribute inside the <embed></embed> object
I thought i can pick it up like any other element (from its id or the tag name) thatís not case.
Say If I have an embed tag as it follows:

<embed src="" id="thePlayer" Ö. ></embed>

I believed that this line will do exactly what I need

document.getElementById('thePlayer').src = path;
But it won't work
i can only guess that it matters that i have put embed inside <object> that works very well but only in IE so itís probably considered as nested element or something
maybe i need to refer 1st the <object> and then the embed but i have no clue how.

Help I need somebody help Ö Beatles lol

P.S. i am using ASp.NET 2.0 as server-side code if it can help at all

04-30-2007, 06:14 PM
check this out.. should help...


04-30-2007, 07:23 PM
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".

Chris, thanks for the link.
but I am afraid it is not very helpful as i am not a javascript guru. lol
so, it's nothing but one more confusion for me.

hmmm ... I was wondering if someone (JS guru) can improvise over the given explanation above?!

Thanks in advance :)

04-30-2007, 07:55 PM
hi there you will need to change the embed tag with innerHtml

wrapper = document.getElementById('mysound-wrapper');
wrapper.innerHTML = '<embed src="a_new_song_.mp3">';

<div id="'mysound-wrapper">
<embed src="a_song_.mp3">

here is some code below that night help....

var songs = new Array(
"Song Title A",
"Song Title B",
"Song Title C",
"Song Title D"

function switchSongs(i)
var file = songs[i * 2];
var title = songs[i * 2 + 1];
var element = document.getElementById('mysound_wrapper');
element.innerHTML = embedSound(file);
var element = document.getElementById('songtitle');
element.innerHTML = title;
var selector = document.getElementById('song_selector');
selector.selectedIndex = i;

function embedSound(sound)
return '<embed src="' + sound + '" autostart="true" ' +
'width="320" height="32">';
<body onLoad="switchSongs(0)">
<h1 align="center">music</h1>
<div align="center">
<select name="song_selector" id="song_selector"
for (i = 0; (i < songs.length); i += 2) {
var file = songs[i];
var title = songs[i + 1];
document.write('<option value="' +
i + '">' +
title + '</option>\n');
<h4>Now Playing: <span id="songtitle"></span></h4>
<div id="mysound_wrapper">
Our music player requires that you enable JavaScript in your
web browser's preferences.

04-30-2007, 11:13 PM
it makes sense to me ... however i will need to try that before i say anything.
Thanks for the code and also thanks for your time Chris.
It is highly appreciated.

05-03-2007, 12:32 PM
Buddy it is perfection. Althrough for you maight be simple for me this is solution for my big problem. Thanks a billion. Now i see that i should not understimate the javascript. Shame on me :(

Regards :)

05-03-2007, 12:48 PM
hey drmak.. i find javascript takes you to the darkside... for me also its still a world of confusion..

its like watching donnie darko,, you think you have got it, then it just confuses you again...


05-03-2007, 09:29 PM
If you want it to work in standard compliant browsers you should use <object> instead of the proprietary (non-standard) <embed> tag.

05-04-2007, 02:40 AM
Ok i am open for suggestion. Actually before this i tried with the object tag so it worked properly only in IE while in FireFox it wasn't appearing at all.
Can you please provide an example of using object that will work for FF too?
Thanks in advance :)