Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prompt a download location instead of downloading directly

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?

like image 650
Gautam Kumar Avatar asked Dec 17 '14 12:12

Gautam Kumar


1 Answers

This is a browser specific setting.

  1. In Chrome: Go to Settings > Downloads > and then select checkbox Ask where to save each file before downloading
  2. In Firefox: Go to Tools > Options, open General tab and select radio button Always ask me where to save files
  3. In Internet Explorer 8: When the download dialog opens up, click Save button and choose the location.
like image 82
Pramod Karandikar Avatar answered Jan 18 '23 23:01

Pramod Karandikar