Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to generate a file in javascript and prompt the user to download?

Tags:

javascript

Is it possible to generate a file in javascript and then prompt the user to download ?

What we would really like to do is the following : we want to make a small html form where an user can edit values in a table, and we would like to be able to generate a csv file from the form and prompt the user to save it on his hard drive. Is it possible in pure javascript ? If not, are there any workarounds ?

Note : I know I could solve this by a round-trip to a server, sending the form and getting a csv file back, but the trick here is that there is no server, the html form will just be generated on a hard drive.

like image 319
madewulf Avatar asked Nov 05 '22 19:11

madewulf


1 Answers

Without a server to download from, you cant get them to download the data like normal.

You could output the csv data to a new browser window and the user could then save this.

like image 96
Mongus Pong Avatar answered Nov 15 '22 05:11

Mongus Pong