I have a need to capture the topics of a search from one of my blog pages and write it to text file for followup. I have been able to capture the input string, however, am n
JavaScript cannot read/write files from the client or write files to the server (directly).
If you want to write files to the server consider using server-side scripts that will interact with your javascript - and example on how to do this with a little bit of PHP.
In terms of client file interaction this is simply impossible for security reasons (unless it is uploaded to the script in which case it is read accessible).
You can however store data on clients - I have previously been using jStorage and highly recommend it. It works cross-browser (even on IE 6) and is extremely easy to use.
If your're using modern browsers which support data-uri, you can create content with javascript and force a download by base64 encoding it and making it compatible with data-uri, then simply pointing window location at it.
This answer demonstrates an HTML-only way to do it.
You can also use a flash helper to take care of this. For instance, Downloadify does this.
Thanks for all the suggestions provided by the members, I was able to perform writing and appending to text file on server. I used html code to acquire my data needed for writing and then called a .php file to do the writing to file. It was a client side versus server side issue and the .php solved it, using fopen, fwrite and fclose.
Techically, when using javascript in a (.hta) file, you can use the ActiveXObject Scripting.FileSystemObject
to access the filesystem, with it there are all the commands you need to do anything to the filesystem that you have permission to do.
var fso=new ActiveXObject("Scripting.FileSystemObject");
if(fso.FolderExists("C:\\Users\\")){
alert("It exists, hello friend!");
}eles{
alert("Doesn't exist, who are you?");
}