tags:

views:

29

answers:

2

I'm working on a web app for my company that will let us do some image tagging stuff, and I'd like to be able to generates results in the form of a CSV file. I can do this easily enough by dumping the CSV data to a div or something on the page and having the user copy it out. I'd rather have them hit the a generate button and have a CSV file downloaded as though they clicked on a link to the result, so they can more easily just save the file somewhere convenient.

Is it possible to simulate this kind of thing with javascript? I basically want to dynamically generate the file and then let them download it, client side.

+1  A: 

With pure javascript you can't do that. Anyway you need some server-side functionality to do that.

antyrat
+6  A: 

You can create a data: URI with media type text/csv, and either create a link to it, or navigate directly to it, in modern browsers.

It won't work in IE. (IE8 can support data: in limited circumstances which don't help you here.) For that browser at least, you'll need to fall back to cut-n-paste or a server backend.

bobince
Bah. Beat me by 14 seconds ;)
David Dorward
Heh. Now we're even!
bobince
+1. Didn't know about this.
z5h
Perfect, thanks muchly!
gct