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

≯℡__Kan透↙ 提交于 2019-12-09 18:03:13

问题


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)


回答1:


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.



来源:https://stackoverflow.com/questions/10000173/data-uri-for-csv-file-in-firefox-not-putting-csv-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!