Storing Small Text
It is actually not a good idea to try to store text file using JS, as this could allow one to access local file systems of your computer or visitor’s website; this is indeed a serious security issue.
Using Ajax or Server Side Language
Using Client Side ActiveX Technology
If you want to do so for your internal purpose or have full faith on your client you can very well do this using ActiveX scripts.
CreateTextFile() creates a file as specified in the first parameter and returns a TextStream object that actually writes to the specified file. The second parameter here accepts a Boolean value. If its value is true that means the file can be overwritten if it exists.
To write any content to the file WriteLine(“Text to write") method of the TextStream object is used. To make the content permanent the file is closed using Close() method. This way we can write a file to store any text data only.
Here's a sample code snippet – (please remove all the whitespace, when you try to run it!)
< span onClick= " file() " ezonclick="true" >Hello < /span > < /p >
var ForAppending = 8;
var TriStateFalse = 0;
var fso = new ActiveXObject("Scripting.FileSystemObject");
var newFile = fso.OpenTextFile("c:\\WINDOWS\\Desktop\\001122.html",
ForWriting, true, TriStateFalse);
< /SCRIPT >
Should You Really Do It?
Secondly, you must enable ActiveXScripts on your PC for the above code snippets to execute properly. At the same time, it's important to understand that you should only allow ActiveXScripts from reliable sources to be executed on your PC to avoid any malicious attacks.