I need to create a new HTML page using javascript. To do that I tried using the window object
let myDocument = window;
myDocument.document.write(`
<html>
<head>
<title>${title}</title>
</head>
<body><section id="print"></section></body>
</html>
`)
My problem is that I would like to generate that on the background and save the result somewhere in my project.
- The user cannot see a new page open or a new window
- The new HTML has to be saved
These are the two problems I have at the moment. I can generate the page, but I could not find out how to do that on the background. My limitation is that the project uses pure javascript so Node.js packages might not work.
Document.writeis no longer suitable for anything like this - Chrome, and possibly webkit browsers in general - does not create a new execution context for the page written withdocument.writeso JavaScript written into the document risks generating errors because you've used the same variable name previously.