i need a textarea that opens a local txt file with the click of a
botton. I dotn want a browse one, I just want one that opens a set
file, like c:/dot/lol.txt . Ty for the help, ill check on the post
constintly
Here's an extract from the file management toolset I'm doing right now.
It works for local pages on IE 5.0 or higher and FireFox 1.0.4 and
higher
Also it should work for all Gesko-based browsers but I did not check
it.
Be careful with line breaks and "@sometext" auto-replacements (Google
Groups is bad on it). It is *much more secure* to get a copy of this
code from my page:
<
http://www.geocities.com/schools_ring/archives/fileRead.zip>
Also watch to double backslashes ("\\" instead of "\") in file path (if
you are under Windows).
..
..
..
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<script type="text/javascript">
/* Collected, corrected and assembled by VK, (e-mail address removed)
* You are welcome to do any imaginable things with this script:
* under your name or any other name (just don't put me on fire
* This (c) is not a (c) and you may remove it. Just remember
* who spent several days for the good of the society
* Piece!
*/
var fso = null;
var privilegeGranted = null;
var runtimeError = '';
function ieFileReader(fullPath) {
out = '';
if (privilegeGranted == null) {
try {
fso = new ActiveXObject('Scripting.FileSystemObject');
privilegeGranted = true;
}
catch (e) {
privilegeGranted = false;
runtimeError = 'Extended privileges are not granted by user';
}
}
if (privilegeGranted) {
try {
var fis = fso.getFile(fullPath).OpenAsTextStream(1,-2);
while (!fis.AtEndOfStream) {
out+= fis.ReadLine();
}
fis.Close();
}
catch (e) {
runtimeError = e.description;
}
}
return out;
}
function ffFileReader(fullPath) {
var out = '';
if (privilegeGranted == null) {
try {
netscape.security.PrivilegeManager
.enablePrivilege('UniversalXPConnect');
netscape.security.PrivilegeManager
.enablePrivilege('UniversalFileRead');
privilegeGranted = true;
}
catch(e) {
privilegeGranted = false;
runtimeError = 'Extended privileges are not granted by user';
}
}
if (privilegeGranted) {
try {
fso = Components.classes['@mozilla.org/file/local;1']
.createInstance(Components.interfaces.nsILocalFile);
fso.initWithPath(fullPath);
var fis =
Components.classes['@mozilla.org/network/file-input-stream;1']
.createInstance(Components.interfaces.nsIFileInputStream);
fis.init(fso,-1,-1,0);
var cnv =
Components.classes['@mozilla.org/intl/scriptableunicodeconverter']
..createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
cnv.charset = 'UTF-8';
var lis =
fis.QueryInterface(Components.interfaces.nsILineInputStream);
var lineData = {};
var count;
do {
count = lis.readLine(lineData);
var line = cnv.ConvertToUnicode(lineData.value);
out+= line;
} while (count);
fis.close();
}
catch (e) {
runtimeError = e.message;
}
}
return out;
}
</script>
<style type="text/css">
body { background-color: #FFFFFF}
var { font: normal 10pt Verdana, Geneva, sans-serif; color: #0000FF;
text-decoration: underline; cursor: hand; cursor
ointer}
</style>
</head>
<body>
<!--[if gte IE 5]>
<p>
<var onclick="alert(ieFileReader('d:\\js\\test.txt'));">Test</var>
</p>
<![endif]-->
<![if ! gte IE 5]>
<p>
<var onclick="alert(ffFileReader('d:\\js\\test.txt'));">Test</var>
</p>
<![endif]>
</body>
</html>