Question: i want the new html file to be created in the same folder in which HTML is present. please help me. am searching a lot , no luck

```
<script>
function makeDocument() {
    var doc = document.implementation.createHTMLDocument("newdoc");
    var p = doc.createElement("p");
    p.innerHTML = "This is a new paragraph.";

    try {
        doc.body.appendChild(p);
    } catch(e) {
        console.log(e);
    }

    var opened = window.open("");
    opened.document.write(doc);
}
</script>

```

Answer: 
Use a back-end server. Because the HTML page and the scripts are executed on the client-side. You can't really create a file on the client-side while the page is loaded in a browser.

The other way around, you won't want the client to create arbitrary files on the server as well. It poses a great security risk and might lead to possible remote code execution (RCE).
You do not have a closing brace on your function

```
<script>
    function makeDocument() {

  var doc = document.implementation.createHTMLDocument("newdoc");
  var p = doc.createElement("p");
  p.innerHTML = "This is a new paragraph.";

  try {
    doc.body.appendChild(p);
  } catch(e) {
    console.log(e);
  }

  var opened = window.open("");
opened.document.write(doc);
}

</script>

```

As for the wording of your question, if you are asking to create a new file that gets saved, then Aviv Lo's answer is what you need