create a dowloadable csv file in a javascript

P

Pif

Hello,

I make calculations and many thinks in a page that result in a
javascript table file. I know how to create a CSV string from this
table in JS, but I would like that when the user click on a given
button, the script launchs and generate a file that is dowloadable
using a dialog box without requesting server.

Can you tell me if it is possible and how I can do that ?

This must be compatible with IE6 (and higher) and latest release of
FF.

Thanks a lot for you help !
 
R

Richard Cornford

I make calculations and many thinks in a page that
result in a javascript table file. I know how to create
a CSV string from this table in JS, but I would like that
when the user click on a given button, the script launchs
and generate a file that is dowloadable using a dialog
box without requesting server.

Can you tell me if it is possible and how I can do that ?

It is not impossible, using data URLs.
This must be compatible with IE6 (and higher) and latest
release of FF.

IE 6 has no support for data URLs, so it looks like you will need to
use server-side code.

Richard.
 
M

Michael Haufe (\TNO\)

IE 6 has no support for data URLs, so it looks like you will need to
use server-side code.

In IE6 you can use document.execCommand("SaveAs", null, "FileName");

Here an example for saving files in IE 6:

http://4umi.com/web/javascript/file...&filename=C:\My+Documents\filename&ext=utf-8#

For the OP, here's an example of prompting a download with a data uri:

http://thenewobjective.com/temp/save.html

For a plain text file, the uri will look something like this:
"data:text/octet-stream," + FileContents
 
G

Garrett Smith

Michael said:
In IE6 you can use document.execCommand("SaveAs", null, "FileName");

[snip]

Good one!

Next step is to take both and create a cross-browser function and test
it in as many browsers.

Questions about your code:
1) why use - document.body.insertBefore( w ); - instead of appendChild?
3) why use window.open?
 
M

Michael Haufe (\TNO\)

Good one!

Next step is to take both and create a cross-browser function and test
it in as many browsers.

Questions about your code:
1) why  use - document.body.insertBefore( w ); - instead of appendChild?
3) why use window.open?


The 4umi.com website is not my domain, only the thenewobjective.com
domain is.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,083
Messages
2,570,591
Members
47,212
Latest member
RobynWiley

Latest Threads

Top