Write to a text file with javascript [duplicated]

0

How can I write to a text file, with javascript. I have this code but it does not work for me:

function WriteFile(filename, data)
        {
            var FileOpener = new ActiveXObject("Scripting.FileSystemObject");
            var FilePointer = FileOpener.OpenTextFile(filename, 2, false);
            FilePointer.WriteLine(data);
            FilePointer.Close();
        }
    
asked by nasck 05.08.2016 в 01:00
source

2 answers

0

The short answer is "you can not".

The long answer is: There is no standard way to write files (on the machine where the browser runs), that works well on all major browsers.

The activex method will work for IE (not for Edge). Mozilla has FileHandle for Firefox, and Google has FileWriter for Chrome.

Note that there is no (reliable) way to make Safari or Edge write files.

I suggest you also read link , and link .

    
answered by 05.08.2016 в 14:24
0

As of HTML5 you can read files. Through the File API. This is the official documentation link

To write files from the browser is a bit more complex. I leave this video where you can see how the API File works in case you need to write files. link

    
answered by 05.08.2016 в 22:57