【问题标题】:How to distinguish Youtube's iframe from other iframes in a webpage?如何区分 Youtube 的 iframe 与网页中的其他 iframe?
【发布时间】:2012-02-07 13:44:30
【问题描述】:


我正在尝试修复 YouTube 视频 iFrame 覆盖和 Z-Index 问题,为此我编写了脚本:

$('iframe').each ->
ifr_source = $(this).attr 'src'
wmode = "wmode=transparent"
if ifr_source.indexOf('?') != -1
$(@).attr 'src', ifr_source + '&' + wmode
else $(@).attr 'src', ifr_source + '?' + wmode


它是用咖啡脚本编写的。
问题是这样的,脚本确实通过在 iframe 中添加 wmode="transparent"parameter 来修复覆盖问题,但在我的页面中还有 10 个其他 iframe,即共享按钮的 iframe 等,并且 wmode 参数也附加到它们。
所以我正在寻找一种方法,我首先会找到 youtube 的 iframe,然后向其中添加 wmode="transparent" 参数。
有什么办法吗??
感谢您的宝贵时间。

编辑 -
我已经看到,在新的 HTML5 youtube 视频中,他们在 iframe 中添加了类,这里是示例代码:

&lt;iframe <strong>class="youtube-player"</strong> type="text/html" width="640" height="385" src="http://www.youtube.com/embed/VIDEO_ID" frameborder="0"&gt;&lt;/iframe&gt;

现在这些视频可以轻松区分,但对于较旧的 youtube 视频,问题仍然存在。

【问题讨论】:

    标签: javascript jquery overlay coffeescript


    【解决方案1】:

    您的 $('iframe') 选择器可以更具体。我不确定您正在操作的 HTML 是什么样的,但是例如,如果您要定位的 iframe 位于 id="watch-player" 的 DIV 中,那么您可以使用:

    $('#watch-player iframe')
    

    并且只会返回出现在 id="watch-player" 的 DIV 中的 iframe。

    【讨论】:

    • 实际上我在不同页面上的相同视频具有不同的布局,所以我不能这样做。我之前已经试过了。
    • 如果无法识别 iframe 可能出现在哪些容器中,也无法识别 iframe 本身的属性——那么就无法为其编写选择器...
    猜你喜欢
    • 1970-01-01
    • 2012-11-25
    • 2015-02-13
    • 1970-01-01
    • 2019-04-18
    • 2013-09-18
    • 2015-09-14
    • 1970-01-01
    • 2023-03-29
    相关资源
    最近更新 更多