Data URI for CSV file in firefox not putting .csv extension

Go To StackoverFlow.com

6

I have a "Download file" href defined in my javascript file as:

    $("#downloadTag").html("<a href=data:text/csv;charset=utf-8," + encodeURIComponent(data) + ">Download</a>");

In chrome it works as expected i.e. when I click on this download link it gives file name as "download.csv". However, in firefox, it puts some gibberish name like "puzdb.part".

Could someone please point me what I am doing wrong?

Thanks

Edit: Here is the jsfiddle demo: http://jsfiddle.net/kLJz9/

Edit #2: I noticed that on windows it does not put .csv extension for chrome as well and behavior for firefox is still same (i.e. .part extension)

2012-04-03 19:40
by test123


3

For Chrome you can designate the file name/extension by adding a download attribute to your anchor tag.

<a href="URI" download="MyFile.csv">Download</a>

This attribute only works in chrome v 14+ and no other browser.

I am also looking for a solution to this problem, but I hope this helps.

EDIT:

the download attribute should fix the issue you are having on windows machines and chrome.

2012-04-24 18:13
by Brad
Thanks for the reply Brad. Data URI works beautifully but I wanted it to be supported by all browsers. :-( It even works perfectly on Mac, it's just windows it doesn't agree with. Please let me know if you do find the solution to this. Thanks - test123 2012-04-25 23:30
There's a bug on Firefox for this: https://bugzilla.mozilla.org/show_bug.cgi?id=622400 (I'm still experiencing on Mac OS X 10.6.8 and Firefox 18.0.2) - Piran 2013-02-07 09:45