4

Do you know any cross-browser method to create and save a file with JavaScript on the client-side?

Considerations:

  1. I can't save it on the server because the file is going to be read from a fiscal printer.
  2. 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.
  3. New ActiveXObject("Scripting.FileSystemObject"); is ONLY for Internet Explorer and even then not for all versions.
  4. 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.
  5. If not JavaScript, what else can I use in my ASP, .Net 4.0, C# web application?

4 Answers 4

4

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?

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Your "this article" link is broken. When linking to off-site pages, it's really important to summarize the information in your text so when the link breaks the information is still useful. See meta.stackoverflow.com/tags/link-only-answers/info "Link rot" "Your answer is in another castle: when is an answer not an answer?"
1

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.

Comments

-1

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

2 Comments

Please read the Question well, I need to write the file in the client not in the server.
your file will be written on client side not on the server .net framework create an object oriented java script of the web service even if you want with this java script your page will write a text file even with a minor post back.
-1

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.