Js downloads cross-domain files if you avoid browsers opening them?

**osspdf,mp4,img**

a tag download these attributes only take effect when downloading files of the same domain
download.js has also been used, but none of the downloaded files can be opened

Jul.22,2021

sets the Content-Disposition in the header of the file http to attachment;filename= file name .


oss can set HTTP headers in batches. When you set Content-Disposition to attachment;, you can download instead of browse


function download(url, params) {
  let tempForm = document.createElement('form')
  tempForm.action = url
  tempForm.method = 'get'
  tempForm.style.display = 'none'
  for (var x in params) {
    let opt = document.createElement('textarea')
    opt.name = x
    opt.value = params[x]
    tempForm.appendChild(opt)
  }
  document.body.appendChild(tempForm)
  tempForm.submit()
  return tempForm
}
const url = 'ali-oss-object-url'
download(url)
.
Menu