如何使用JavaScript创建和保存文本文件 [英] How to create and save a text file with JavaScript
本文介绍了如何使用JavaScript创建和保存文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您知道在客户端使用JavaScript创建和保存文件的任何跨浏览器方法吗?
Do you know any cross-browser method to create and save a file with JavaScript on the client-side?
注意事项:
- 我无法将其保存在服务器上,因为将从财务打印机读取文件。
- 服务器可以无法访问客户端。这很明显,因为我们正在谈论Web中的Web应用程序,因此服务器无法访问客户端文件夹。
- 新建
ActiveXObject( Scripting.FileSystemObject );
仅适用于Internet Explorer,甚至不适用于所有版本。 - 我们正在谈论在财务打印机上进行打印,所以我不能问超市中的收银员下载文本文件并将其保存在财务打印机可以读取的文件夹中。
- 如果没有JavaScript,我还可以在ASP.Net中使用什么4.0,C#Web应用程序?
- I can't save it on the server because the file is going to be read from a fiscal printer.
- The server can't access the client. This is obvious because we are talking about a web application in the web, so the server can't access a client folder.
- New
ActiveXObject("Scripting.FileSystemObject");
is ONLY for Internet Explorer and even then not for all versions. - We are talking about printing on a fiscal printer, so I can't ask the cashier in the supermarket to download the text file and save it in a folder where the fiscal printer can read it.
- If not JavaScript, what else can I use in my ASP, .Net 4.0, C# web application?
推荐答案
基本上,您说的是,我们在谈论网络应用程序。您是否知道有任何将文件保存到硬盘上的Web应用程序(除cookie之外),而没有先显示下载提示?
Basically, you said it, "we are talking about a web application." Do you know any web applications that save a file to your hard drive (besides cookies) without showing you a download prompt first?
话虽如此,浏览器已经开始提供一个超越cookie的持久性API 。 (例如,参见本文。)但是,这种解决方案无法满足您的要求是跨浏览器。
Having said that, browsers have started to offer a persistence API that goes beyond cookies. (See, for example, this article.) But such a solution wouldn't meet your requirement of being cross-browser.
这篇关于如何使用JavaScript创建和保存文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文