/**
* 替换img标签src属性
* @param content
* @param path
*/
function imgsSrc(content, path) {
var imgreg = /<img.*?>/gi;
content=content.replace(imgreg,function(imgsrc){
imgsrc = imgsrc.replace(/src=(?:"\s*([^"]*)\s*"|‘\s*([^‘]*)\s*‘|(\S+))/i,"src=\""+path+"$1\"");
return imgsrc;
});
//不是微信内核浏览器
if(!is_weixin()) {
content = content.replace(/(<img[^>]*?src=[‘""]([^‘""]*?)[‘""][^>]*?>)/g, ‘<a href="$2">$1</a>‘);
}
return content;
}
/**
* 判断微信内核浏览器
* @returns {Boolean}
*/
function is_weixin() {
var ua = navigator.userAgent.toLowerCase();
if(ua.match(/MicroMessenger/i) == "micromessenger") {
return true;
} else {
return false;
}
}
本文出自 “8731262” 博客,请务必保留此出处http://8741262.blog.51cto.com/8731262/1567549