function download(url, title) {
let a = document.createElement('a')
a.href = url
a.download = title
a.click()
}
如果想使用参数 title
重命名下载,必须遵循同源策略,如果跨域了,就按 url
末尾的文件名命名。
比如本地localhost运行代码:
<a download="test.mp4" href="http://xxx.cn/abc.mp4">test</a>
下载下来就 abc.mp4
。
此外,title
需要自行添加文件后缀,如 .jpg
。