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

发布于 2024-12-26 01:43:21 字数 454 浏览 2 评论 0原文

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

?wmode=transparent

我该怎么做?

Youtube 嵌入代码的示例如下:

<iframe width="515" height="292" src="http://www.youtube.com/embed/p8IB-5PbL9U" frameborder="0" allowfullscreen></iframe>

这样做的原因是因为我有一个位于 Youtube 视频后面的 javascript 菜单,并且我读到这就是修复它的方法。

客户端根本不具备技术性,只是让他们从 Youtube 获取嵌入代码很困难,因此需要动态添加。

I have several Youtube videos that are added through a CMS by a client. I need to add the following to all Youtube src links:

?wmode=transparent

How would I do that?

An example of the Youtube embed code is as follows:

<iframe width="515" height="292" src="http://www.youtube.com/embed/p8IB-5PbL9U" frameborder="0" allowfullscreen></iframe>

The reason for doing this is because I have a javascript menu that is going behind a Youtube video and I've read that this is how you fix it.

The client isn't technical at all and just having them get the embed code from Youtube is a struggle, so it needs to be added dynamically.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

半世晨晓 2025-01-02 01:43:21

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

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

If you just need to add ?wmode=transparent to all the frames, have this JS code:

window.onload = function() {
    var frames = document.getElementsByTagName("iframe");
    for (var i = 0; i < frames.length; i++) {
        frames[i].src += "?wmode=transparent";
    }
}
子栖 2025-01-02 01:43:21

您固定使用 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>

Are you fixed on using the iframe? It makes this a lot more difficult as you are unable to access the underlying object directly. If you can, it would be better to directly embed the object on your page as such

<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>
荆棘i 2025-01-02 01:43:21

根据您的 CMS,您可以通过纯 PHP 来完成此操作,只需将其添加到每个 url 的末尾,或者您的或让 jQuery 为您完成工作。

$('iframe').each(function() {
    $(this).attr("src", $(this).attr("src") + '?wmode=transparent')
});

Depending on your CMS you could do this through plain PHP, by just adding it at the end of each url, or your or make jQuery do the work for you.

$('iframe').each(function() {
    $(this).attr("src", $(this).attr("src") + '?wmode=transparent')
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文