Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

112
Views
create html document given a document name from html text input

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

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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>'));
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!