这段代码已经工作了6个月,然后它突然开始抛出这段代码。对于Tumblr主题,我们必须为iframe youtube视频问题创建一个解决方案。
显然抛出错误的行是:
if(theVidURL.indexOf('youtu.be') >= 0)
错误:TypeError:theVidURL未定义
以下是代码的其余部分:
function replaceThumbnailImg(){
// var classes = $('article.video').attr('class').split(' ');
articles = $('article.video');
articles.each(function(){
var headers = $(this).find('header');
var theVidURL = $(this).find('.source_link').attr('href');
var theVidURLArray = null;
if(theVidURL.indexOf('youtu.be') >= 0){
theVidURLArray = theVidURL.split('.be/');
if(typeof theVidURLArray[1]!='undefined'){theVidURLArray = theVidURLArray[1].split('/');}
} else {
theVidURLArray = theVidURL.split('v=');
if(typeof theVidURLArray[1]!='undefined'){theVidURLArray = theVidURLArray[1].split('&');}
theVidURLArray = theVidURLArray[0].split('?');
}
if(theVidURL.indexOf('youtu') >= 0){
headers.each(function(){
theThumbURL = 'http://img.youtube.com/vi/'+theVidURLArray[0]+'/0.jpg';
$(this).html('<img src="'+theThumbURL+'" />');
});
}
// $('header').html('');
});
}