Web application - Write To .txt file with Javascript FileObject.Write

Viewed 58

I'm trying to re-purpose some older java script code that I use in order to create a text file via an intranet web app. The following code creates text files that are picked up and processed by a third party application running on the same device...

<script>
    function WriteTransferFile(location) {
        var fileSystemObject = new ActiveXObject("Scripting.FileSystemObject");
        var fileObject = fileSystemObject.CreateTextFile("C:\\transfer\\transfer.txt", true);
        fileObject.Write(location);
        fileObject.Close();
        return location;
    }
</script>

<script id="writetransfer">
    function writetransfer() {
        var Location = document.getElementById('lblCommand');
        var Command = Location.innerHTML;
        WriteTransferFile(Command);
        }
</script>

This works fine for a single text string to be pasted into a text file, but I now need to create a file which takes 4 different fields from the web page and writes them on to consecutive lines. I've played around with the above but any attempt to add a second line of text overwrites the first line instead creating a new one below it. Desired output...

Field 1

Field 2

Field 3

Field 4

Any ideas how I might accomplish this?

I'm aware this probably isn't the sleekest solution, but there are no concerns regarding the suppression of active X security settings as this is for a closed system with access to local intranet only.

Thanks

Steve

0 Answers
Related