h5點擊下載按鈕,下載excel或者word


根據url下載文件的幾種方法

1:直接跳轉

window.open(img)

2:直接跳轉

window.location.href=img

3:生成a鏈接跳轉

       var link = document.createElement('a')
       link.style.display = 'none'
       link.href = img //文件路徑
       link.download = name//文件名
       document.head.appendChild(link)
       link.click()
       document.head.removeChild(link)    

4:生成iframe下載

      var iframe = document.createElement('iframe');
          iframe.style.display = 'none';
          iframe.src = "javascript: '<script>location.href=\"" + img + "\"<\/script>'";
          document.getElementsByTagName('body')[0].appendChild(iframe);

5:生成form表單下載

       var form = document.createElement('form');
          console.log(form);
          form.action = img;
          document.getElementsByTagName('body')[0].appendChild(form);
          form.submit();

  


免責聲明!

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



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