How to change the value of embed src with JavaScript?

前端 未结 3 1580
礼貌的吻别
礼貌的吻别 2020-12-06 12:16

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

相关标签:
3条回答
  • 2020-12-06 12:50

    It 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)
    }
    
    0 讨论(0)
  • 2020-12-06 12:50

    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>

    0 讨论(0)
  • 2020-12-06 13:01

    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

    0 讨论(0)
提交回复
热议问题