笔记:html下载文件的几种方式

2,029 阅读1分钟

下载的几种方式

打开下载链接的方式

  • html方式(a标签)

    <a href="https://whereyourfilepathto.com/xxx.zip" target="_blank"></a>
    

    行为:打开一个新的窗口并触发浏览器的下载行为

  • js方式

    • window.open

      window.open('https://whereyourfilepathto.com/xxx.zip');
      

      行为:打开一个新的窗口并触发浏览器的下载行为

    • window.location.assign

      window.location.assign('https://whereyourfilepathto.com/xxx.zip');
      

      行为:不打开新的窗口并触发浏览器的下载行为

      推荐这种

:D 喜欢就点个👍吧