0

I've got a hta-script that saves values of text-inputs to a .txt file locally. That works great, with one exception: It saves the .txt file as ANSI - what I need to do is save it with UTF-8 charset.

Is there an easy way to do that?

<!DOCTYPE html>
<html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <link rel="stylesheet" type="text/css" href="style.css" media="screen" />

 <hta:application id="rndme"
     applicationname="file saving test"
     caption="yes"
     showintaskbar="yes"
     singleinstance="yes"  />

    </head>
  <body>



<input type="text" id="data" name="data0" value="Titel" onfocus="this.value=''"></input>
<input type="button" id="button1" value="Speichern" onclick="save('titel.txt', data0.value ); alert('Trainer Name wurde erfolgreich gespeichert.');"/>
</div>


<script>

function load(filename) {
    var fso, file, text;
    fso = new ActiveXObject("Scripting.FileSystemObject");
      file = fso.OpenTextFile(filename, 1, false);
    //text = file.readAll();
      file.Close();
    return text;
} //end load()

function save(filename, strData) {
    var fso, file;
    fso = new ActiveXObject("Scripting.FileSystemObject");
    file = fso.CreateTextFile(filename, 2, false);
    file.write(strData);
    file.Close();
    return file;
}//end save()

function append(filename, strData) {
  return save( filename , load(filename) + strData );
}//end append();


</script>
</body></html>
user692942
  • 16,398
  • 7
  • 76
  • 175
  • [This answer](https://stackoverflow.com/a/52341876/692942) deals with how to encode to UTF-8 and explains why your current method won't work. – user692942 Aug 07 '19 at 10:59
  • Hi Lankymart, thank you. Unfortunately I do not know how to implement that code as I can't write (or read) VBScript. Is that hard to do? – S learning JS Aug 07 '19 at 14:00
  • Sorry I didn’t realise the HTA was using JScript, the syntax shouldn’t be much different the same COM objects and methods are being used. – user692942 Aug 07 '19 at 14:12
  • This might help you a bit more - [Writing UTF8 text to file](//stackoverflow.com/a/25850620) – user692942 Aug 07 '19 at 14:56

0 Answers0