admin管理员组文章数量:1356522
What is the best way to achieve the below in latest latest browsers (with html5 support). I mainly target Google Chrome.
In my application, data is manipulated through javascript and needs to write output to the file system with a browser prompt (save as dialog). I am not sure about the security restrictions to write to file system, but I am not planning anonymous write (but user is prompted, and selects the location).
I see saveAs not natively supported yet. With my research, I see few options.
- .js
- a.download (.download.html)
- web filesystem
- object URLs
FileServer falls back to 2,3,4 if no native support and I may use it. But, I don't find a way to open a Save As dialog. It just save a file in default location (downloads folder in mac).
Which option would you use to get a good support in latest browsers? How can get open the Save As dialog and let the user name the file.
Thanks.
What is the best way to achieve the below in latest latest browsers (with html5 support). I mainly target Google Chrome.
In my application, data is manipulated through javascript and needs to write output to the file system with a browser prompt (save as dialog). I am not sure about the security restrictions to write to file system, but I am not planning anonymous write (but user is prompted, and selects the location).
I see saveAs not natively supported yet. With my research, I see few options.
- https://github./eligrey/FileSaver.js
- a.download (http://html5-demos.appspot./static/a.download.html)
- web filesystem
- object URLs
FileServer falls back to 2,3,4 if no native support and I may use it. But, I don't find a way to open a Save As dialog. It just save a file in default location (downloads folder in mac).
Which option would you use to get a good support in latest browsers? How can get open the Save As dialog and let the user name the file.
Thanks.
Share Improve this question asked Mar 4, 2013 at 22:20 bsrbsr 58.8k88 gold badges218 silver badges321 bronze badges 6- 1 what type of file is it. usually you just output it to the browser with the correct headers and the browser takes care of the save as dialog for you. – nathan hayfield Commented Mar 4, 2013 at 22:22
- say, a js object, which will serialize to csv / json upon save. – bsr Commented Mar 4, 2013 at 22:23
- stackoverflow./questions/4639372/export-to-csv-in-jquery – nathan hayfield Commented Mar 4, 2013 at 22:25
-
Since your mainly target is Google Chrome, a 5º option is making your application a Chrome Package App and use the
chrome.fileSystem
API. – user2587420 Commented Jul 21, 2013 at 21:46 -
1
In Google Chrome (and currently no other browsers), you can set a
download
attribute on your link (<a href="rec.csv" download="save_name.csv">
). However, this does not use a prompt; it downloads directly to the user's downloads folder. – apsillers Commented Jul 24, 2013 at 20:08
1 Answer
Reset to default 4I agree with Nathan Hayfield. The browser will handle the save dialog box for you. Setting the header Content-Disposition will send the response back as an attachment and the browser will handle it from there. eg.
content.Headers.Add("Content-Disposition", "attachment; filename=export.csv");
本文标签: htmlJavascript save data to file system (with user prompt)Stack Overflow
版权声明:本文标题:html - Javascript save data to file system (with user prompt) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744068733a2585493.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论