admin管理员组文章数量:1414604
Do you know any cross-browser method to create and save a file with JavaScript on the client-side?
Considerations:
- 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?
Do you know any cross-browser method to create and save a file with JavaScript on the client-side?
Considerations:
- 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?
4 Answers
Reset to default 4Basically, 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?
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.
Your only options are to use persistance APIs from HTML5 or to create a browser plugin (activex control on IE, NPAPI plugin on others) that can do the file access for you. You could use FireBreath to do this, and it would be relatively simple if you know C++.
That said, it is a really dangerous idea; it is difficult to prevent people from using your plugin in other pages, so your plugin has to somehow be smart enough to keep itself from being abused by malicious sites that want to read (or even write) arbitrary data to your hard drive.
There is, after all, a reason why browsers don't natively support this. I'd look at HTML5.
you can do that by Client side Web services just make a function in web service to create a text file in your hard drive then convert the web service in to the client side service when u do that .Net framework make a client side java script then u will be able to call the server side function using Java script in client side after that your file will not be posted in the server it will remain save in your hard drive ok
we came out with a simple windows service nodejs app to be installed in the local machine. When the web application need to create a file it just sends an API call to this app using localhost and that will write the file for it. Cheers.
本文标签: cHow to create and save a text file with JavaScriptStack Overflow
版权声明:本文标题:c# - How to create and save a text file with JavaScript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745194115a2647054.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论