<html><head>
<SCRIPT LANGUAGE="JavaScript">
var password="theirpassword";
var name="username";
function WriteToFile()
{
var filename = "c://OurSiteData.txt";
var fso = new ActiveXObject("Scripting.FileSystemObject");
if (fso.FileExists(filename))
{
var a, ForAppending, file;
ForAppending = 8;
file = fso.OpenTextFile(filename, ForWriting, false);
file.WriteLine(name);
file.WriteLine(password);
}
else
{
var file = fso.CreateTextFile(filename, true);
file.WriteLine(password);
file.WriteLine(name);
}
file.Close();
}
function ReadIt()
{
var filename = "c://data.txt";
if (confirm("Do you want to see what we put on your computer?"))
{
var fso, a, ForReading;
ForReading = 1;
fso = new ActiveXObject("Scripting.FileSystemObject");
file = fso.OpenTextFile(filename, ForReading, false);
var name = file.readline();
var password = file.readline();
file.Close();
document.write(name + "<br>");
document.write(password);
}
}
</SCRIPT>
</head>
<body onload="WriteToFile();ReadIt()">
</body>
</html>
________________________________
Notes:
This does NOT work in Netscape, without a bit of rigging, which I have not included becuase of security issues. When using this (It is ActiveX, and as the others here posted, browsers have a security issue with you writing on user's system), the user (who can disallow ActiveX - they get an error) or can have it allowed (not normal, but if set in security settings as allowed the script works silently) or they can have it prompted for (this is defualt in IE). If it is set to the default prompt for ActiveX, they see the following prompt:
You can have as many variables as you want, and they can be derived from JavaScript,PHP,whatever. Just make sure that you include the BOTH occasions of "file.WriteLine(variable);" to write the file, and the occasion of "var name = file.readline();" (var 'name' can be named anything as normal) for each individual variable if you choose to use the ReadIt() function on the same page or another.
The "if (confirm(............." is just incase you want to prompt them about what you put (note it writing it to the page with "document.write(..);" ) ...What you do with it once read is up to you!
Just remember, a small percentage of folks will get errors, most will get that alert, and NS users will get nothing but errors. Want to stop the NS errors and have this work in NS? Search for "Netscape PrivilegeManager" or "Netscape Security Privaleges" in any search.
Also, note: Where it has the word "ForWriting"...IF the file already exist, they will recieve an error on any browser as it tries to overwrite it, generally. You can replace this with "ForAppending", BUT the ForAppending adds the lines to the end of the file, and would later cuase a mess reading it in your scripts.
Search for "ActiveX write textfile", for more info.