内容详情图片地址转换
var str = '<div><img a="b" alt="123" src="/news/img/01.jpg" width=400 height=400><img src="http://www.otherdomain.com/news/img/02.jpg" width=400 height=400><img src="http://www.domain.com/news/img/03.jpg" width=400 height=400><img src="/news/img/04.jpg" width=400 height=400></div>';
var reg = /<img(.*?)src="([^"]+)"/gi;
var newUrl;
var domain = location.protocol + '//' + location.hostname +'/';
str = str.replace(reg, function(img, attrs, src) {
newUrl = 'src="' + src;
if(!((src.indexOf('http://') == 0) || (src.indexOf('https://') == 0))) {
newUrl = 'src="' + domain + src;
}
return '<img' + attrs + newUrl + '"';
})
return str;
网友评论