如何动态添加wmode = transparent到Youtube嵌入代码?

Rob*_*Rob 9 javascript embed youtube

我有几个Youtube视频,由客户通过CMS添加.我需要将以下内容添加到所有Youtube src链接:

?wmode=transparent
Run Code Online (Sandbox Code Playgroud)

我该怎么办?

Youtube嵌入代码的示例如下:

<iframe width="515" height="292" src="http://www.youtube.com/embed/p8IB-5PbL9U" frameborder="0" allowfullscreen></iframe>
Run Code Online (Sandbox Code Playgroud)

这样做的原因是因为我有一个jout菜单落后于Youtube视频,我已经读到这就是你如何修复它.

客户端根本不是技术人员,只是让他们从Youtube获取嵌入代码是一件很困难的事情,因此需要动态添加.

Sha*_*ard 11

如果您只需要添加?wmode=transparent到所有框架,请使用此JS代码:

window.onload = function() {
    var frames = document.getElementsByTagName("iframe");
    for (var i = 0; i < frames.length; i++) {
        frames[i].src += "?wmode=transparent";
    }
}
Run Code Online (Sandbox Code Playgroud)


jor*_*aul 5

您是否已修复使用iframe?由于您无法直接访问底层对象,因此这会变得更加困难.如果可以的话,最好直接在页面上嵌入对象

<object width="515" height="292">
<param name="movie" value="http://www.youtube.com/v/p8IB-5PbL9U"></param>
<param name="allowFullScreen" value="true"></param>
<param name="wmode" value="transparent"></param>
<embed src="http://www.youtube.com/v/p8IB-5PbL9U"
  type="application/x-shockwave-flash"
  allowfullscreen="true"
  wmode="transparent"
  width="515" height="292">
</embed>
</object>
Run Code Online (Sandbox Code Playgroud)