Advanced Search

Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Can you open, modify, and close a txt document using JavaScript?

  1. #1
    Join Date
    Oct 2006
    Location
    Shanghai, China
    Posts
    36
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Can you open, modify, and close a txt document using JavaScript?

    Hi,

    Is there a script that will open a text file, write some info into it, and then close it?

    Basicly I'm looking for a JavaScript alternative to fopen, fwrite, and fclose in PHP.

    Thanks!

    Joe

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    No, of course not. A site that can read and modify the user's files?

    You can use cookies via document.cookie, but that's as close as you're getting.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Oct 2006
    Location
    Shanghai, China
    Posts
    36
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    What I'm looking for is something like this:
    Code:
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    var ForAppending = 8;
    var TristateTrue = -1;
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    var newLine = fso.OpenTextFile("C:/test/database.txt", ForAppending, true, TristateTrue);
    newLine.Write("Hello World!\n")
    newLine.Close
    -->
    </SCRIPT>
    But why isn't each entry on it's own line? If I run the script a few times it looks like
    Hello World!Hello World!Hello World!
    when I view it in Notepad but it looks like
    Hello World!
    Hello World!
    Hello World!

    when I view it in IE or paste it into a Word document.

    Thanks,

    Joe

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,154
    Thanks
    261
    Thanked 690 Times in 678 Posts

    Default

    ActiveX can do that. That and Java. (Note: Java isn't Javascript. Think applets.)
    PHP, and other server side codes, can likewise edit things on the server.

    ActiveX isn't javascript. It's a part of Javascript, kinda, but it's Internet Explorer only, and, as you can tell from what you're doing, it is a security risk in some ways.

    As for just adding a new line, I would assume that \n would work. However, you might want to add a carriage return character as well: \r\n
    Not sure if that will help, and ActiveX isn't my thing, so can't tell you much more.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Oct 2006
    Location
    Shanghai, China
    Posts
    36
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thanks.

    It is actually putting the line breaks in there, they just don't show up when I view the file with Notepad. I probably have to save the text file in a different format or something. I guess it doesn't really matter, as long as the script can see the line breaks!

    do you know how to turn off that annoying activex security warning every time the script runs?

    Thanks,

    Joe

  6. #6
    Join Date
    Oct 2006
    Posts
    75
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    activeX settings like that are client side, obviuosly nothing can be done on the server side to bypass these settings, other wise the world would be overrun by viruses, that eventually mutate into something that'll tear your head off when you get to close to the computer LMAO

    LMAO sry im high on caffeen, had a morbid moment LMAO

  7. #7
    Join Date
    Oct 2006
    Location
    Shanghai, China
    Posts
    36
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    That's right.

    I'm trying to write a little script that will append or modify a database on my desktop. It's just that the alert is annoying every time I run the script so I'd like to turn it off, though I do worry about opening myself up to a virus attack.

    Oh well, thank you everyone who replied.

    Joe

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    the-disturbed:

    The reason the linebreaks aren't visible in Notepad is that you're using a UNIX-style linebreak (\n) instead of a Windows-style linebreak (\r\n), and Notepad is too stupid to work it out.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,154
    Thanks
    261
    Thanked 690 Times in 678 Posts

    Default

    kasei, I'm sure there's something, probably in advanced settings, to turn off the warning popup in Internet Explorer. We thought you meant disabling the warning through the script for anyone who viewed the page. It's a local setting, so the script can't do that, but the user can disable it if they want.

    Twey, I mentioned \r\n above... not sure if kasei tried it or not, but s/he said it didn't work in notepad. Might there be another reason?
    And, good to know unix vs. windows. Does \r do anything to unix? (Rather, would it be invalid to use that just in case, so it works on windows too?)
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    UNIX editors won't like \r\n very much, but they're usually smart enough to pick up on it and convert it accordingly. It's pretty safe to use except for sensitive things like shell scripts.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •