Setting the file name using encodeURIComponent () to allow the user to load the data file

Ok, so I have this webpage page that gets its data using AJAX requests (in javascript using jQuery). After the data has been downloaded to the users browser, I want them to download the specified data without a second request from the server.

To do this, I found this little code (in Javascript):

window.location = 'data:text/csv;charset=utf8,' + encodeURIComponent(someCSVtext); 

This does what I want, but it always names the file "download.csv"

Is it possible to specify a file name if the user has the option β€œalways download file” installed in their browser (thus, you cannot rename the file)?

+4
source share

All Articles