a href自定义下载文件名

var url = 'http://xxxx.com/xxxx.zip;

      var xhr = new XMLHttpRequest();

      xhr.open('GET', url, true);

      xhr.responseType = 'blob';

      xhr.onload = function () {

        if (this.status === 200) {

          var blob = new Blob([this.response]);

          var blobUrl = window.URL.createObjectURL(blob);

          var a = document.createElement('a');

          a.href = blobUrl;

          //设置下载文件的名字

          a.download = '新文件名'

          a.click();

          window.URL.revokeObjectURL(blobUrl);

        }

      };

      xhr.send();

相关推荐

  1. a href定义下载文件名

    2023-12-07 04:48:01       66 阅读
  2. 若依定义文件上传下载

    2023-12-07 04:48:01       20 阅读
  3. 报表定义导出文件名

    2023-12-07 04:48:01       60 阅读
  4. UnityShader定义cginc文件

    2023-12-07 04:48:01       55 阅读
  5. 二.定义文件

    2023-12-07 04:48:01       43 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-07 04:48:01       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-07 04:48:01       100 阅读
  3. 在Django里面运行非项目文件

    2023-12-07 04:48:01       82 阅读
  4. Python语言-面向对象

    2023-12-07 04:48:01       91 阅读

热门阅读

  1. 设计模式&委派模式(Delegate Pattern)

    2023-12-07 04:48:01       58 阅读
  2. 【LeetCode】258. 各位相加

    2023-12-07 04:48:01       61 阅读
  3. Vue中的组件通信:从子到父的数据传递

    2023-12-07 04:48:01       65 阅读
  4. C++设计模式——建造者模式(Builder)

    2023-12-07 04:48:01       76 阅读
  5. ES6拓展API

    2023-12-07 04:48:01       55 阅读
  6. Socket.D 网络应用协议,首版发布!

    2023-12-07 04:48:01       59 阅读
  7. 字符指针变量

    2023-12-07 04:48:01       54 阅读
  8. 数据结构-基数排序

    2023-12-07 04:48:01       62 阅读
  9. 利用 Python 进行数据分析实验(二)

    2023-12-07 04:48:01       61 阅读
  10. linux系统调用介绍

    2023-12-07 04:48:01       65 阅读
  11. Vue的methods中定时器的变量报错问题

    2023-12-07 04:48:01       60 阅读
  12. C++ day50 买卖股票最佳时机

    2023-12-07 04:48:01       63 阅读
  13. linux优化-平均负载率

    2023-12-07 04:48:01       57 阅读
  14. 数据结构 / 队列 / 循环队列 / 结构体定义和创建

    2023-12-07 04:48:01       66 阅读
  15. vue的模板语法

    2023-12-07 04:48:01       66 阅读