Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create HTML file with JavaScript

I'm looking for a way to use a JavaScript function to create a new HTML file in the local directory. Is this possible?

Thanks

like image 406
intl Avatar asked Sep 30 '10 05:09

intl


People also ask

Can you create an HTML file with JavaScript?

You can add HTML to a newly created document the same way you usually do: by using methods such as append() , appendChild() , and other DOM-related JavaScript methods. In the code above, a new HTML document is created using the createHTMLDocument() method of the DOMImplementation interface and the Hello World!

How do you add JavaScript to a HTML file?

To include an external JavaScript file, we can use the script tag with the attribute src . You've already used the src attribute when using images. The value for the src attribute should be the path to your JavaScript file. This script tag should be included between the <head> tags in your HTML document.

Can we write a file in JavaScript?

There is a built-in Module or in-built library in NodeJs which handles all the writing operations called fs (File-System). It is basically a JavaScript program (fs. js) where function for writing operations is written. Import fs-module in the program and use functions to write text to files in the system.


1 Answers

(Client Side) Yes, but you might need to create a new ActiveX Object, therefore the browser should be IE only.

(Server Side) Just use any server-side scripting language (JS is not one).

like image 188
Ruel Avatar answered Oct 02 '22 18:10

Ruel