function download(url, title) {
let a = document.createElement('a')
a.href = url
a.download = title
a.click()
}
If you want to use the parameter title
to rename download, you must follow the same origin policy, if a cross-domain, you press the url
end of the filename naming.
Such as local localhost run the code:
<a download="test.mp4" href="http://xxx.cn/abc.mp4">test</a>
Download it abc.mp4
.
In addition, the title
need to add their own file suffix, such as .jpg
.