zl程序教程

您现在的位置是:首页 >  后端

当前栏目

js下载

2023-09-11 14:17:22 时间

https://blog.csdn.net/believet93/article/details/99821853

1、使用<a>标签

<a href="../../static/xxx.xlsx" download="xxx.xlsx">下载</a>
直接点击可以下载,需要注意的是download属性,当不加download属性时,如果文件格式为txt、pdf、jpg等浏览器支持直接打开的文件格式,那么不会下载,而是浏览器直接打开;添加download属性之后,就会下载,并且下载文件默认命名为你download属性的值。(参考: https://blog.csdn.net/jsnancy/article/details/80824801)

 

2、使用window.open()

window.open("../../static/xxx.xlsx")

window.open("https://mp.csdn.net/postedit/static/xxx.xlsx")
当然,下载的资源可以是本地的,也可以是网上的。