Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I would like to know if there is any way to generate a text/xml file in javascript. I want users to be able to fill out a page form when they are offline, save the data, and then use the saved file at a later point in time. The browser will be IE, most likely IE7.

Thanks

share|improve this question
add comment (requires an account with 50 reputation)

2 Answers

up vote 0 down vote accepted

The files should be stored on client filesystems, right?

In general, saving data on client's computer by a web script would be considered a security breach. I would avoid doing so but if it's one of your project requirements, you can give it a try.

Since the target platform would be IE, you can try ActiveX. Example code (not tested):

var fso  = new ActiveXObject("Scripting.FileSystemObject");
var fh = fso.CreateTextFile("c:\\path\\file.txt", true);
fh.WriteLine("Some text");
fh.Close();
share|improve this answer
Thanks. I suppose all IE versions support this? At least down to ie7? And if i want to save the file as an xml, all i need to do is to change ".txt" to ".xml", right? – Johan Oct 7 '11 at 8:39
ActiveX was introduced abaut IE3 :). And for extensions - yes. – Przemek Oct 7 '11 at 8:48
add comment (requires an account with 50 reputation)

You might have to use Flash in order to access the user's filesystem to save the file. That is the way most client-side components work if they need to create a file wholly on the client.

Time to learn ActionScript, and say goodbye to iDevices compatibility!

share|improve this answer
add comment (requires an account with 50 reputation)

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.