0

I need to write some data to local file using fetch. When i try to do my method, it is not working. Maybe fetch can not write files - i dont know. Thank you!

let recv = document.getElementById("recv").value;
  let money = document.getElementById("cost").value;
  fetch(recv+'.txt')
  .then(response => response.text())
  .then(data => {
    // Do something with your data
    let hernmon = data;
   int1 = parseInt(hernmon);
   int2 = parseInt(money);
   int3 = parseInt(moneyint)
   let outmon = int1 + int2;
    data = outmon;
  });
  fetch(name+'.txt')
  .then(response => response.text())
  .then(data => {
    // Do something with your data
    let hernmon = data;
   int1 = parseInt(hernmon);
   int2 = parseInt(money);
   int3 = parseInt(moneyint)
   let incmon = int3 - int2;
    data = incmon;
  });
  return

1 Answers1

0

You can not directly write to a local file, since that would cause massive security problems, but you can create files in the browser using Blob and URL.createObjectURL. All recent browsers support this and provide it as a download link for the user. You can suggest a file name via the download attribute of the link, in browsers that support the download attribute. As with any other download, the user downloading the file will have the final say on the file name though...