提取和替换(仅限YouTube)Iframe src [英] extract and replace (YouTube ONLY) Iframe src
本文介绍了提取和替换(仅限YouTube)Iframe src的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果YouTube iframe html
If a YouTube iframe html is
<iframe width="560" height="315" src="http://www.youtube.com/embed/VIDEOID" frameborder="0" allowfullscreen></iframe>
jquery应该测试iframe src
到看看前29个字符是否匹配 http://www.youtube.com/embed/
The jquery should test the iframe src
to see if the first 29 characters match http://www.youtube.com/embed/
如果有的话应用jquery在 / embed /
之后提取 VIDEOID
并用 http替换iframe src ://www.redirect.mysite.com/?id = VIDEOID
if it does apply a jquery to extract the VIDEOID
after /embed/
and replace the iframe src with http://www.redirect.mysite.com/?id=VIDEOID
所以iframe的src低于
so the iframe's src below
<iframe width="560" height="315" src="http://www.youtube.com/embed/EhrYQrLBiTQ" frameborder="0" allowfullscreen></iframe>
应替换为
<iframe width="560" height="315" src="http://www.redirect.mysite.com/?id=EhrYQrLBiTQ" frameborder="0" allowfullscreen></iframe>
推荐答案
看到这个小提琴: http://jsfiddle.net/maniator/cRFgv/
代码:
$('iframe').each(function(){
this.src = this.src.replace('http://www.youtube.com/embed/',
'http://www.redirect.mysite.com/?id=');
});
这篇关于提取和替换(仅限YouTube)Iframe src的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文