Text Area that opens a txt file with a click of a botton

X

xtheriaultx

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
 
R

Randy Webb

(e-mail address removed) said the following on 11/4/2005 11:41 PM:
i need a textarea that opens a local txt file with the click of a
botton.

Open it where? And, where is the .html file that you want to use? On
your HD or on a server?
I dotn want a browse one, I just want one that opens a set
file, like c:/dot/lol.txt .

Again, open it where?
 
D

Danny

I gather he means, he wants to load an external .txt file content to a
textarea element .value property without a page reload just a file
query/receival. I thought about recommending to use XMLHttpRequest object
through http://localhost server, but I think he wants a premade, no 'help'
per se, could look it up but, tis alright :).


Danny
 
R

Randy Webb

Danny said the following on 11/5/2005 12:47 AM:
I gather he means, he wants to load an external .txt file content to a
textarea element .value property without a page reload just a file
query/receival. I thought about recommending to use XMLHttpRequest object
through http://localhost server, but I think he wants a premade, no 'help'
per se, could look it up but, tis alright :).

What the hell are you babbling about?

Don't answer. Considering that you seem to lack the ability to quote
anything although you have the ability to snip out the reply, any answer
you give to me won't be worth the pixels it takes to display it.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?
 
V

VK

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:pointer}
</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>
 
V

VK

holy crap thats complex

Say "thank you" to Microsoft and Mozilla Foundation. They seem both in
competition in this domain: "Who will manage to express simple things
in the most complex way". So far Mozilla is the absolute champion, but
it may change - whatch the race :).

I'm currently finishing my jsFileManager which will be an easy to use
wrapper over all this holy mess. Whatch the post in this newsgroup.
 
E

Evertjan.

wrote on 07 nov 2005 in comp.lang.javascript:
holy crap thats complex

[please always quote on usenet, this is not email]

without quoting it looks simple.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top