Reputation: 983
I am creating a CSV element in JavaScript and then simulating a click to download the respective file.
But instead of downloading directly i want it to open a download prompt to choose the location of file to be downloaded.
var csvString = Papa.unparse(result,{
quotes: false,
delimiter: ",",
newline: "\r\n"
});
var a = document.createElement('a');
a.href = 'data:attachment/csv,' + escape(csvString);
a.download = "download.csv";
a.click();
How can this be done?
Upvotes: 15
Views: 13544
Reputation: 5329
This is a browser specific setting.
Settings > Downloads >
and then select checkbox
Ask where to save each file before downloading
Settings > Downloads >
and then enable
Ask me what to do with each download
Tools > Options
, open General
tab and select radio button Always ask me where to save files
Save
button and choose the location.Upvotes: 19
Reputation: 443
You will have to use the File System Access API which is not supported by all browsers but seems to be coming. If you are developing something for "internal use", you might be good with that. If you are developing for the big public, then you might still implement it, but along with it put some try-catch
to fall back to the default download.
Read this answer to a similar question for further information.
Upvotes: 2