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

Discussion in 'Javascript' started by xtheriaultx@gmail.com, Nov 5, 2005.

  1. Guest

    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
    , Nov 5, 2005
    #1
    1. Advertising

  2. Randy Webb Guest

    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?

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
    Randy Webb, Nov 5, 2005
    #2
    1. Advertising

  3. Danny Guest

    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
    Danny, Nov 5, 2005
    #3
  4. Randy Webb Guest

    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?
    Randy Webb, Nov 5, 2005
    #4
  5. VK Guest

    wrote:
    > 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,
    * 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>
    VK, Nov 5, 2005
    #5
  6. Guest

    holy crap thats complex
    , Nov 7, 2005
    #6
  7. VK Guest

    wrote:
    > 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.
    VK, Nov 7, 2005
    #7
  8. Evertjan. Guest

    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.

    --
    Evertjan.
    The Netherlands.
    (Replace all crosses with dots in my emailaddress)
    Evertjan., Nov 7, 2005
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Celebrate

    Box around RadioList Botton

    Celebrate, Aug 22, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    363
    Celebrate
    Aug 22, 2003
  2. Sameen
    Replies:
    2
    Views:
    425
    Victor Bazarov
    Aug 29, 2005
  3. Maulik shah via .NET 247

    Datagrid ItemCreated event & Edit botton - vb.net

    Maulik shah via .NET 247, May 18, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    359
    Maulik shah via .NET 247
    May 18, 2005
  4. msnews.microsoft.com

    How can show "abc" in textbox when click one botton

    msnews.microsoft.com, Oct 2, 2003, in forum: ASP General
    Replies:
    9
    Views:
    135
    Ray at
    Oct 2, 2003
  5. Dustin  Carroll

    How to get right mouse botton click on image

    Dustin Carroll, May 10, 2006, in forum: Javascript
    Replies:
    3
    Views:
    113
    Thomas 'PointedEars' Lahn
    May 20, 2006
Loading...

Share This Page