我正在尝试修复 YouTube 视频 iFrame 覆盖和 Z-Index 问题,为此我编写了脚本:
$('iframe').each ->
ifr_source = $(this).attr 'src'
wmode = "wmode=透明"
if ifr_source.indexOf('?') != -1
$(@).attr 'src', ifr_source + '&' + w模式
别的
$(@).attr 'src', ifr_source + '?' + wmode
它是用coffeescript编写的。
问题是这样的,脚本确实通过在iframe中添加wmode="transparent"
参数来解决覆盖问题,但在我的页面还有其他 10 个 iframe,即共享按钮等的 iframe,并且 wmode 参数也附加到它们。
所以我正在寻找一种方法,首先找到 youtube 的 iframe,然后添加wmode="transparent"
参数。
有什么方法可以做到这一点吗?
感谢您的时间。
编辑 -
我发现在新的 HTML5 youtube 视频中,他们在 iframe 中添加了类,这里是示例代码:
所以现在这些视频可以很容易区分,但旧版 YouTube 视频的问题仍然相同。
I am trying to fix YouTube Video iFrame Overlay and Z-Index Issue, for this i wrote script :
$('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
Its written in coffeescript.
The problem is this, script do fix the overlay issue by adding wmode="transparent"
parameter in iframe but in my page there are also 10 others iframes i.e iframes of sharing buttons etc. and the wmode parameter also get attached to them.
So I was looking for a way that i will first find the youtube's iframe then add wmode="transparent"
parameter to it.
Is there any way to do this??
Thanks for your time.
Edit -
I have seen that in new HTML5 youtube videos they have added class in iframe here is the sample code:
<iframe class="youtube-player" type="text/html" width="640" height="385" src="http://www.youtube.com/embed/VIDEO_ID" frameborder="0"></iframe>
So now these video can be distinguish easily, but the problem remains same for older youtube videos.
发布评论
评论(1)
您的 $('iframe') 选择器可以变得更加具体。我不确定您正在操作的 HTML 是什么样子,但例如,如果您想要定位的 iframe 位于 id="watch-player" 的 DIV 中,那么您可以使用:
并且仅在 DIV 内出现 iframe id="watch-player" 将被返回。
your $('iframe') selector can be made to be more specific. I'm not sure what the HTML you're operating on looks like, but for instance, if the iframe you wanted to target was in a DIV with id="watch-player" then you could use:
and only iframes occurring inside DIVs with id="watch-player" would be returned.