当前位置:网站首页>Dynamically determine file types through links
Dynamically determine file types through links
2022-07-26 10:18:00 【CS beat you】
1, Determine the type of link :
// The judgment is the picture 、 video 、ex、word One of them
function checkform(f_content){
console.log(" link :"+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, The echo : If it's pictures and vidoe Just show , Otherwise, directly through a Click the note to download
// Incoming link judgment
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"> Click to download </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"> Click to download </a>\n';
}else{
// Can't find
}According to the effect :

边栏推荐
- SQL优化的魅力!从 30248s 到 0.001s
- 简单化构造函数的继承方法(一)- 组合继承
- Redis realizes the correct posture of token bucket
- Wechat applet learning notes 2
- 【Halcon视觉】数组
- 分布式网络通信框架:本地服务怎么发布成RPC服务
- Interview shock 68: why does TCP need three handshakes?
- Production of a-modal drag function in antui
- PHP one-time request lifecycle
- 【C#语言】具名类型和匿名类型
猜你喜欢

分布式网络通信框架:本地服务怎么发布成RPC服务

Leetcode 504. Hex number

Server memory failure prediction can actually do this!

Necessary for beginners: debug breakpoint debugging skills in idea and common breakpoint skills

What will the new Fuzhou Xiamen railway bring to Fujian coastal areas?

【Halcon视觉】软件编程思路

Vs Code configures go locale and successfully installs go related plug-ins in vscode problem: Tools failed to install

数通基础-Telnet远程管理设备

Transform between tree and array in JS (hide the children field if the child node of the tree is empty)

Cause: could't make a guess for solution
随机推荐
数通基础-网络基础知识
Study notes at the end of summer vacation
【C#语言】LINQ概述
面试第一家公司的面试题及答案(一)
Leetcode 504. 七进制数
Leetcode 504. Hex number
Vs Code configures go locale and successfully installs go related plug-ins in vscode problem: Tools failed to install
数通基础-STP原理
Learning about opencv (4)
Mysql5.7.25 master-slave replication (one-way)
【Halcon视觉】图像滤波
INSTALL_FAILED_SHARED_USER_INCOMPATIBLE错误解决方式
Vs2019 configuring opencv
Okaleido生态核心权益OKA,尽在聚变Mining模式
Error in render: "typeerror: cannot read properties of undefined (reading 'length')" --- error when calling interface
Opencv image processing
[Qualcomm][Network] qti服务分析
Meeting OA project (III) -- my meeting (meeting seating and submission for approval)
In Net 6.0
【Halcon视觉】编程逻辑