I have just begun to learn JS. I am trying to change the value of embed src in the tag present in my HTML code. But am unable to do so with the following code I've written -
HTML -
<ol>
<li><a href=".swf"
onclick="showGame(this);return false;">Kitty Throw</a></li>
</ol>
<embed id="gameHolder" src=".jpg"
quality="high" menu ="false" width="550" height="400"
type="application/x-shockwave-flash"
pluginspage="" /></center>
JS:
function showGame(whichgame){var source=whichgame.getAttribute("href");
var game=document.getElementById("gameHolder");
game.setAttribute("src",source);}
I want the JS to display the flash file selected in the gameHolder space which by default holds an image. I am unable to do this with just my beginner knowledge of JS, also please explain the code as you use it.
I have just begun to learn JS. I am trying to change the value of embed src in the tag present in my HTML code. But am unable to do so with the following code I've written -
HTML -
<ol>
<li><a href="http://embedgames.ru/wp-content/games/kitty-throw.swf"
onclick="showGame(this);return false;">Kitty Throw</a></li>
</ol>
<embed id="gameHolder" src="http://pictat.com/i/2011/7/10/32479playscrnba.jpg"
quality="high" menu ="false" width="550" height="400"
type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer" /></center>
JS:
function showGame(whichgame){var source=whichgame.getAttribute("href");
var game=document.getElementById("gameHolder");
game.setAttribute("src",source);}
I want the JS to display the flash file selected in the gameHolder space which by default holds an image. I am unable to do this with just my beginner knowledge of JS, also please explain the code as you use it.
Share Improve this question edited Jan 28, 2012 at 17:24 PeeHaa 72.7k60 gold badges194 silver badges264 bronze badges asked Jul 11, 2011 at 6:16 user837598user837598 3- Can you include some more context, such as relevant HTML or how you actually call this function. Further, have you considered a scripting library such as JQuery or Prototype? – hayesgm Commented Jul 11, 2011 at 6:20
- 2 Have you tried game.src = source; ? – Andrey M. Commented Jul 11, 2011 at 6:23
- Your code seems to be working find. In which part do you have problem? – Saeed Neamati Commented Jul 11, 2011 at 6:24
3 Answers
Reset to default 18It may depend on the browser and the type of the embedded object, how you have to change the object(for example there are special methods for flash-movies like Play() , but the object isn't a flash-movie at the begin)
A common way is to replace the whole embed-node with a new <embed>
:
function showGame(whichgame){
var source=whichgame.getAttribute("href");
var game=document.getElementById("gameHolder");
var clone=game.cloneNode(true);
clone.setAttribute('src',source);
game.parentNode.replaceChild(clone,game)
}
It works also if you change param src only
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">
<EMBED id="movie" src="first.swf" "></EMBED>
</OBJECT>
<ul>
<li name='moviename'>first.swf</li>
<li name='moviename'>second.swf</li>
<li name='moviename'>third.swf</li>
</ul>
<script type="text/javascript">
var names=document.getElementsByName("moviename");
for (var i = names.length - 1; i >= 0; i--) {
names[i].addEventListener("click", myFunction);
function myFunction() {
document.getElementById("movie").setAttribute("src", this.innerHTML);
}
}
</script>
you can set src of embed tag in javascript, for that you must have to write your embed tag in javascript like below example :
function onclickofSomething() {
$('#IDOfParentElement').html("<embed type='application/x-mplayer2' pluginspage='http:///www.microsoft.com/Windows/MediaPlayer/' src='" + "<%=YourVideoPath%>" + "YourVideoName" + ID + ".mp4/wmv" + "' autostart='1' showstatusbar='1' enabled='1' showdisplay='1' showcontrols='1' width='630' height='380'></embed>");
}
you can also see below url : need to set video file name using javascript http://www.webdeveloper.com/forum/showthread.php?53086-how-to-change-the-src-in-lt-embed-gt-using-javascript http://www.daniweb.com/web-development/javascript-dhtml-ajax/threads/16626/how-to-change-the-the-value-of-src-in-embed-using-javascript