-1

I have to record some text strings from an HTML webpage into a text file to be processed by another program.

I've tried many javascript examples but so far I haven't even managed to get a file.

<script>

    function wFile(filepath, output) {
        var txtFile = new File([""], filepath);
        txtFile.open("w"); //
        txtFile.writeln(output);
        txtFile.close();
    }

    wFile("C:/temp/test.txt","some text");

</script>

F12 results in: Uncaught TypeError: txtFile.open is not a function

Zakaria Acharki
  • 66,747
  • 15
  • 75
  • 101
Gerie1th
  • 3
  • 1
  • You cannot save a file on the server from the client directly (you can save it locally under a sandbox if you'd like). It's unclear what you are trying to do. You probably need to call a URL that can write the files for you – Ruan Mendes Apr 04 '19 at 18:03
  • I'm used to asp.net and creating files at the server side is just a single line. In case javascript is not handy i could look for php the achieve the same. – Gerie1th Apr 04 '19 at 18:51

1 Answers1

0

<script> tags are used on HTML webpages for client-side Javascript. You can't create local files from a web browser as the browser is sand boxed from both the users computer and the server that sent the files.

You are probably looking for nodejs.org which is a server-side platform for Javascript.

Xeoncross
  • 55,620
  • 80
  • 262
  • 364