用blob下載音頻並改名


在用a標簽下載音頻時,跳轉為播放,而不是下載

fetch(url).then(res => res.blob()).then(blob => {
          const a = document.createElement('a');
          document.body.appendChild(a)
          a.style.display = 'none'
          // 使用獲取到的blob對象創建的url
          const url = window.URL.createObjectURL(blob);
          a.href = url;
          // 指定下載的文件名
          a.download = 'xxxx.mp3';
          a.click();
          document.body.removeChild(a)
          // 移除blob對象的url
          window.URL.revokeObjectURL(url);
        });

不過,在下載第二個時,瀏覽器出現提示‘是否允許下載多個’的問題


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM