извлечение и замена (ТОЛЬКО для YouTube) Iframe src

#jquery #iframe #youtube

#jquery #iframe #YouTube

Вопрос:

Если HTML-код iframe YouTube является

 <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/

если это произойдет, примените jquery для извлечения VIDEOID after /embed/ и замены iframe src на http://www.redirect.mysite.com/?id=VIDEOID

итак, src iframe ниже

 <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>
  

Ответ №1:

Посмотрите на эту скрипку:http://jsfiddle.net/maniator/cRFgv

Код:

 $('iframe').each(function(){
    this.src = this.src.replace('http://www.youtube.com/embed/', 
                                         'http://www.redirect.mysite.com/?id=');
});
  

Комментарии:

1. Не то, что я искал, а только очень небольшую конфигурацию

2. $('iframe').each(function(){ this.src = this.src.replace('http://www.youtube.com/embed/', 'http://www.redirect.mysite.com/?id='); });

3. @Yusaf теперь все должно быть в snuf:-D