admin管理员组文章数量:1203198
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="" 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.
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.
Share Improve this question edited Jan 11, 2012 at 11:06 Rob asked Jan 11, 2012 at 10:53 RobRob 6,37025 gold badges90 silver badges194 bronze badges 2- Need a little more info: What CMS? Is there any JavaScript frameworks (e.g. jQuery, MooTools or other)? How much videos are on a single page? – Oleksandr Skrypnyk Commented Jan 11, 2012 at 11:14
- I like this answer, unfortunately adding the parameter dynamically didn't work for me, I had to go back to using the older <embed> code... – DrCord Commented Nov 12, 2013 at 16:39
3 Answers
Reset to default 11If 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";
}
}
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>
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')
});
本文标签: javascriptHow to dynamically add wmodetransparent to Youtube embed codeStack Overflow
版权声明:本文标题:javascript - How to dynamically add wmode=transparent to Youtube embed code? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738662427a2105503.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论