iT邦幫忙

0

chrome如何點開csv檔的網頁鏈結會自動下載

  • 分享至 

  • xImage

我想請問一下chrome如何點開csv檔的網頁鏈結會自動下載
同樣的link 在 firefox 點進去會下載.csv檔,但chrome會跳到分頁顯示csv裡的內容。

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

1
player
iT邦大師 1 級 ‧ 2022-10-20 18:42:14

1.HTML download Attribute
https://www.w3schools.com/tags/att_a_download.asp
但早期的瀏覽器可能無效

2.WebServer端在送出檔案內容前
送出HTTP檔頭
ContentType:application/download
這是通知瀏覽器下載檔案用的
還有別忘了傳檔名
Content-Disposition:attachment;filename=TestFile.csv

alanotmt iT邦新手 4 級 ‧ 2022-10-21 09:50:17 檢舉

因為我的下載鏈結是js透過API產生的,所以JS後面要打什麼碼才可以指定下載?

0
obarisk
iT邦研究生 2 級 ‧ 2022-10-21 17:58:05

網頁伺服器需要適當(正確)的 content-type
瀏覽器設定指定的 content-type 要執行的動作

我要發表回答

立即登入回答