tags:

views:

78

answers:

2

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.

+1  A: 

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.

Mongus Pong
A: 

In pure javascript, no.

You'd need a server side script to generate the file and save it temporarily/ in memory, and then present a force-download dialogue to the user.

Suggest you take Fungus' route and use javascript to write it to a browser window, then instructing the user how to save it (Copy > Paste ... etc).

Cheers, Sean

seanxe