我撰寫了一個 NodeJS/Express 應用程式,它在用戶按下按鈕時生成和下載一個 excel 檔案(使用 ExcelJS 創建)。當用戶按下按鈕時,會生成檔案,然后將其下載到用戶的默認下載位置。我希望用戶能夠在按下按鈕后選擇他們想要下載檔案的位置。這可能嗎?
我當前的 JavaScript 代碼如下:
export_button.onclick = async function() {
await fetch('/download', {
method: 'POST'
})
.then(resp => resp.blob())
.then(blob => {
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.style.display = 'none';
a.href = url;
a.download = 'document.xlsx';
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
});
}
uj5u.com熱心網友回復:
這在最新的基于 Chrome 的瀏覽器(Chrome、Edge、Opera)的桌面版本中是可能的。
當前支持:
事實上,我們有一個方法叫做:<pdf-file>.saveAs()。

Visual Studio Code 的在線版本是另一個最近的用戶:https : //vscode.dev/。
Apple and Firefox are likely to drag their feet on this one citing privacy/security concerns for at least the next few months though.
uj5u.com熱心網友回復:
我不相信這是可能的,不。此行為由用戶瀏覽器中的設定控制。對于大多數瀏覽器,甚至可能是所有瀏覽器,默認行為是始終將檔案下載到默認位置,而不顯示用戶可以更改其目的地或檔案名的提示。可以理解,您無法從 JavaScript 更改用戶的瀏覽器設定。
很高興看到我錯了,我沒有意識到檔案系統訪問 API Cetin Sert 的答案所描述的存在。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/343621.html
標籤:javascript html 节点.js 表达 精益求精
