Setting filename using encodeURIComponent() to let user download data file

4.4k Views Asked by At

Alright, so I have this webpage page that gets its data using AJAX requests (in javascript using JQuery). Once the data has been loaded on to the users browser I want to let them download said data without having to request it from the server again.

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

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

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

Is there a way I can preset the filename assuming the user has an "always download file" option set in their browser (thus don't get a chance to rename the file)?

0

There are 0 best solutions below