1,判断链接的类型:
//判断是图片、视频、ex、word的其中一种
function checkform(f_content){
console.log("链接:"+f_content);
var fileext=f_content.substring(f_content.lastIndexOf("."),f_content.lastIndexOf("?"));
fileType=fileext.toLowerCase();
console.log(fileType);
if(
fileType == ".jpg" || fileType == ".JPG" || fileType == "image/jpeg" ||
fileType == ".png" || fileType == ".PNG" || fileType == "image/png" ||
fileType == ".gif" || fileType == ".GIF" || fileType == "image/gif"
){
return 0;
}
if (fileType=='.mp4'||fileType=='.m2v'||fileType=='.mkv'){
return 1;
}
if (fileType=='.xls'||fileType=='.xlsx'){
return 2;
}
if (fileType=='.doc'||fileType=='.docx'){
return 3;
}
return -1;
}
2,回显:如果是图片和vidoe就直接显示,否则直接通过a便签点击下载
//传入链接判断
var type = checkform(document);
console.log("-===============:"+type);
if(type==0){
dom += '<img style="width: 100%;margin-bottom: 10px" src="'+document+'">'
}else if(type==1){
dom += '<video th:src="'+document+'" controls\n'
+ ' style="width: 100%;margin-bottom: 10px"></video>'
}else if(type==2){
//dom += '<iframe id="excelIframe" src=https://view.officeapps.live.com/op/view.aspx?src="'+document+'" width=\'100%\' height=\'100%\' frameborder=\'1\'></iframe>'
var image = 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1575615615720&di=94fe53f0421941f41cf9d21527e5f093&imgtype=0&src=http%3A%2F%2Fwww.szrcpx.com%2Fuploads%2F181203%2F1-1Q203161202104.jpg';
dom+='<img style="width: 40px;margin-bottom: 10px" src="'+image+'"><a href="'+document+'" \n'
+ '\t\t \t\tdownload="test.png">点击下载</a>\n';
}else if(type==3){
var image = 'http://img3.imgtn.bdimg.com/it/u=3838238180,3232741685&fm=26&gp=0.jpg';
dom+='<img style="width: 40px;margin-bottom: 10px" src="'+image+'"><a href="'+document+'" \n'
+ '\t\t \t\tdownload="test.png">点击下载</a>\n';
}else{
//找不到
}
显示效果: