Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic <embed> "src"

Status
Not open for further replies.

masoal

Programmer
Mar 26, 2002
15
ES
Hi all,
I want to dynamically change the SRC of an <EMBED> element but it seems that it doesn't work altough that if I retrieve the src attribute after change it, it's ok.

<body>
...
<EMBED name="video" id="video" src="" width="200" height="198" showControls="0" enablecontextmenu="0" fullScreen="0" autostart="false">
...
</body>
<script>
document.all.video.src="MOV1.MPG";
alert(video.src);
document.all.video.play();
</script>

It doesn't matter if the path it's relative or absolute, the final result is the same:

"JavaScript error: The object doesn't accept this property or method"

Any suggestions?
 
Sorry, I've forgotten to tell that it just have to work under IE.

Thanks !!!
 
Embed is not a standard tag, which doesn't actually mean anything in the same way that a standard tag does - it's an artificial collection of undefined data objects which get passed to a plug-in at the time it is parsed; these tags only have meaning to the plug-in. Alterting its DOM values later on would be unlikely to work the way you expected, and indeed it doesn't seem to. I suggest you look into the attributes of the plug-in you wish to use and see if you can communicate directly with it to set the source uri there. Your first problem, however, may well be getting an empty-source Embed tag to bind to a plug-in in the first place. I can tell you why your code doesn't work, therefore, but not whether it can be done.
 
Oh, that's right, I've noticed that if I don't initialize the "type" attribute the code is very wateful because I haven't loaded the corresponding plugin ...
I've tried to do it in another way and this time works much better: I dynamically replace the whole EMBED tag with all their attributes instead of changing only the SRC attribute. It works fine !!!... I don't know if it's the cleanest way to do it but it reaches what I needed.

Thanks MOrac !!!
 
very interesting!

A:can you post that working example to change the whole EMBED tag? thanks.

B:I am trying to develop a page with 3 videos and I want to make them dynamic, click video1= play video1,stop video2+3. and so on... any ideas?
 
I finally didn't apply the dynamic insert and remove of content because I had memory problems. I mean that I wanted to do something like you, to play and stop different videos so after executed the Stop command I removed the innerHtml of the embeded object but the result was a memory problem as the object didn't exist and the MediaPlayer thread couldn't accesed.
So, in my case, the final solution has been to put several floating MediaPlayer objects and changing their visibility and position property depending on the video that I wanted to play.

If you still need to dynamically insert and remove html, you could you use "innerHtml" to insert code into an element.

I hope it helps !!!!

Hope it helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top