rgky

1、如果图片头信息有

  "Content-Disposition", "attachment; filename="fileName"

  那么直接使用 iframe 设置属性src浏览器就会默认下载

  $("#iframe").attr("src",imgSrc);

2、使用window另存为

  var fileObj=window.open(fileURL,"_blank","height=0,width=0,toolbar=no,menubar=no,scrollbars=no,resizable=on,location=no,status=no");

  fileObj.window.close();
  fileObj.document.execCommand("SaveAs");
  fileObj.close();

3、iframe另存为方式测试为成功,待有时间再试

注意:
下载文件时,如果文件名存在中文,需要做url转码 URLEncoder.encode(fileName, "UTF-8") ,头信息不支持中文
ajax不支持下载文件:https://www.cnblogs.com/nuccch/p/7151228.html

分类:

技术点:

相关文章:

  • 2021-05-28
  • 2021-11-29
  • 2021-12-12
  • 2022-12-23
  • 2021-07-04
  • 2021-06-12
  • 2022-01-21
  • 2022-01-29
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-30
  • 2021-11-06
  • 2022-02-09
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案