Я программирую приложение с elecrtonjs и застрял.
Итак, на моей странице есть этот HTML:
<a href="./step1.html" id="next"><span onclick="writeToFile();return false">Next ></span></a`>
И в javasriptfile я сохраняю вещи в файл в каталоге:
var fs = require('fs');
function writeToFile() {
//alert(document.getElementsByTagName("input").length);
var text = "";
// Change the content of the file as you want
// or either set fileContent to null to create an empty file
for (var i = document.getElementsByTagName("input").length - 1; i >= 0; i--) {
text += document.getElementsByTagName("input")[i].getAttribute("name")+":\n";
text += document.getElementsByTagName("input")[i].value+"\n";
}
// The absolute path of the new file with its name
var filepath = "mynewfile.txt";
fs.appendFile(filepath, text, (err) => {
if (err) throw err;
console.log("The file was succesfully saved!");
});
}
Код перенаправляет правильно, но не добавляет пользовательский ввод в указанный файл.
Я неправильно рассчитал время? Я пытался
onbeforeunload
Спасибо за помощь.