Results 1 to 2 of 2

Thread: Textare to .txt

  1. #1
    Join Date
    Jun 2008
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Textare to .txt

    Hi all

    I have this little script that I found a while ago,

    Code:
    <script>
    function save()
    {
    str = document.forms[4].textarea.value;
    mydoc = window.open();
    mydoc.document.write(str);
    mydoc.document.execCommand("saveAs",true,"CallLog.txt");
    mydoc.document.close();
    }
    </script>
    and im now wondering if there is any Client Side way of making the text add to a text file rather than overwriting it?

    Thanks
    Kirt

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    You know all this is for IE only, right?

    Without looking it up, you might be able to read CallLog.txt to the window using execCommand as part of the process of writing to the widow before saving. This wouldn't actually append to the file, it would still overwrite it, but the result would be as if it had been appended to.

    Edit: I just did look it up, you cannot. Here's the list of Commands (command identifiers) available for execCommand:

    http://msdn.microsoft.com/en-us/libr...49(VS.85).aspx

    Open is listed as not supported. There are no other ones that look like they would read a file.


    There is another method for actually appending to a file, but there will be Active X warnings, even for a live page using these methods, as they could write malicious files:

    Code:
    <script type="text/javascript">
    // Instantiate a File System ActiveX Object:
    var a, fso = new ActiveXObject("Scripting.FileSystemObject");
    // Invoke the method:
    try {
    a = fso.CreateTextFile("c:\\webwork2\\testfile.txt", false);
    }catch(e){
    a = fso.OpenTextFile("c:\\webwork2\\testfile.txt", 8)
    }
    // Do something with it:
    a.WriteLine("This is a test. 4");
    // Close the connection:
    a.Close();
    </script>
    Last edited by jscheuer1; 08-04-2008 at 10:38 AM. Reason: add info
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •