How to change the value of embed src with JavaScript?

前端 未结 3 1592
礼貌的吻别
礼貌的吻别 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 :

    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)
    }
    

提交回复
热议问题