im trying to create a html document with a name given from a html text input. i dont know how i can write that file to a location though; i want to write the file to a specific directory. this is what I have figured out so far:
var title = document.getElementById("docTitle").value
function append(){
console.log("creating new document")
createHTMLDocument(title)
FileSystem.writeFile(title, htmlContent, (error) => {/*handle error*/});
}
the input value from the html text input is assigned to a variable which is put into the writeFile, and function append() is activated by a html button. ".html" will be put into the text input as the name so no extra code is needed to create the document specifically as html.
please help
The browser is a sandbox from which most of the user's operating system or filesystem isn't available to a website, this due to security concerns.
This means you will have to offer the file you create as if it is a download;
const button = document.getElementById('download');
function download(filename, text) {
const element = document.createElement('a');
element.setAttribute('href', 'data:text/html;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
button.addEventListener('click', () => download('test', '<h1>Hello world</h1>'));