Files

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Giacomin Alan

    Files

    I have to do an exercise for school where in a HTML file I have to
    read and write some words from a txt file. the two files are in
    network, not in local. can someone help me? thanks a lot.

    **Alan**
  • Grant Wagner

    #2
    Re: Files

    "Giacomin Alan" <g.alan86@virgi lio.it> wrote in message
    news:79197cc5.0 501181007.41cda 5bb@posting.goo gle.com...[color=blue]
    >I have to do an exercise for school where in a HTML file I have to
    > read and write some words from a txt file. the two files are in
    > network, not in local. can someone help me? thanks a lot.[/color]

    Impossible. Client-side JavaScript in an HTML document in the default
    security environment has no ability to read or write files on the local
    hard disk.

    JavaScript can store information in a cookie, but the underlying
    implementation is under the control of the browser. In other words,
    sure, IE stores cookies as files, so you can argue that "JavaScript lets
    you read and write files", but it is hardly the level of control that
    one expects when you say "you can read and write files".

    Anyway, if that is an exercise, you need a better instructor, one who
    understands that client-side JavaScript in an HTML document in the
    default security environment has no ability to read or write files on
    the local hard disk.

    --
    Grant Wagner <gwagner@agrico reunited.com>
    comp.lang.javas cript FAQ - http://jibbering.com/faq


    Comment

    • McKirahan

      #3
      Re: Files

      "Giacomin Alan" <g.alan86@virgi lio.it> wrote in message
      news:79197cc5.0 501181007.41cda 5bb@posting.goo gle.com...[color=blue]
      > I have to do an exercise for school where in a HTML file I have to
      > read and write some words from a txt file. the two files are in
      > network, not in local. can someone help me? thanks a lot.
      >
      > **Alan**[/color]

      Will this do?

      <html>
      <head>
      <title>readwrit .htm</title>
      <script type="text/javascript">
      function readwrit(parm) {
      var sFIL = "C:\\Temp\\read writ.txt";
      var oFSO = new ActiveXObject(" Scripting.FileS ystemObject");
      var oOTF;
      if (parm == 1) {
      oOTF = oFSO.OpenTextFi le(sFIL,1);
      document.form1. data.value = oOTF.ReadAll();
      } else if (parm == 2) {
      // "Permission denied" error on secord try!
      oOTF = oFSO.OpenTextFi le(sFIL,2,true) ;
      oOTF.Write(docu ment.form1.data .value)
      }
      }
      </script>
      </head>
      <body>
      <form name="form1">
      <textarea name="data" cols="60" rows="10"></textarea>
      <br>
      <input type="button" value="Read" onclick="readwr it(1)">
      &nbsp;
      <input type="button" value="Write" onclick="readwr it(2)">
      &nbsp;
      <input type="reset" value="Clear">
      </form>
      </body>
      </html>


      Comment

      Working...