HTML5 - file question?

Associate
Joined
25 Feb 2006
Posts
194
HTML5 - local storage?

Anyone know how to create and write a simple text file using javascript from a web browser? The file needs to be stored locally on the client. Whats the easiest way? I dont mind if it doesnt work in all browsers. Thanks for any help!
 
Last edited:
There are a few options for this - it depends exactly on what you want to do, but most likely you'll want to look at local storage - it has very good support from the major browsers.

Thanks but "local storage" seems to only store key-value pairs in a mini-database which can only be accessed by the same browser.

Is there a way of getting the browser to write a text file in the users file-system? (I'm trying to get some data out of a browser into another application)
 
Last edited:
Can I ask what exactly is it that you want to write to this file and what is it being used for?

Yes of course. There are three types of file I want to create for my university projects, but I'm having trouble finding the best way to do it..

(1) ".dxf" - text file readable by CAD systems. My HTML5/Javascript software would generate the content on the client. The dxf file could then be taken by usb-stick to a laser cutter, for example, or opened in a CAD system.
(2) ".csv" - comma separated variables, for reading by Excel. The Javascript would create the content - these would be results of some scientific simulations.
(3) ".txt" - general bits and pieces, so can be opened by Notepad or whatever

I dont need to save binary files, just plain old ASCII.

Thanks!!
 
Last edited:
All you can do is provide a stream to a file that the user will need to manually save.

Hows that done? Supposing my client Javascript is just

var mycontent = new String("hello mum");

How does the user save mycontent into a file called "anyoldname.dxf" ?
I'm happy for the user to pick anyoldname and location, but the filename needs to end with .dxf
 
Last edited:
Its possible for the user to save a local file on the client in Silverlight, which I've done previously, but I'm looking for a way of doing the same thing in native HTML5/JS for a uni project. But I guess the answer is no.

Someone said send it to the server and use a MIME type to download it and save on the client, but does anyone know how to do that?
 
Last edited:
Back
Top Bottom