This message was edited by Josh Code at 2004-5-1 9:17:44
: Say you have a HTML Forms page and you want to take the data that is entered on that page and save it to the users hard drive, but in a comma delimited text file. Can JS be used for this?? If so, could someone provide some examples please??
:
: Thanks
: David
:
You can write files to a person's harddrive. To deal with security problems, the viewer of the page will always be asked for permission to make the file, however.
JScript(something made by Microsoft) has a File object that you can use.
There are ActiveX objects to use. Click the link below for a reading example.
http://www.theserverside.com/discussions/thread.tss?thread_id=18599
This object can also be used for writing files.
take a look at this too.
http://www.webreference.com/js/tips/001031.html
I tried it out with Netscape and Internet Explorer and it only worked for Internet Explorer.
Here is the code I used:
<html>
<SCRIPT LANGUAGE="JavaScript">
<!--
function WriteFile()
{
var TristateFalse = 0;
var ForWriting = 2;
myActiveXObject = new ActiveXObject("Scripting.FileSystemObject");
myActiveXObject.CreateTextFile("c:\\test.txt");
file = myActiveXObject.GetFile("c:\\test.txt");
text = file.OpenAsTextStream(ForWriting, TristateFalse);
text.Write("Hello World");
text.Close();
}
// -->
</SCRIPT>
<body onload="WriteFile()">
</body>
</html>