UserDy
UserDy

Reputation: 357

JS: Submit HTML file and place file code within div

Basically what im looking for is a way for the user to upload an html file when they click <input type="file"/> button.

When the user selects an HTML file, I want to take the HTML code and place it within a div. Can this be done without server-side languages?

Upvotes: 2

Views: 883

Answers (1)

Bhaskara
Bhaskara

Reputation: 601

Using javascript You cannot browse on a clients disk files. However your case is possible. Please check the below stackover question which exactly matches your requirement. Refer Paolo Moretti answer. Here is the link: How to open a local disk file with Javascript?

As you want to browse/upload only HTML files add "accept" to your input file type like this:

<input type="file" accept="text/html"/>

In HTML5 you can use file extensions as the accept like this:

<input type="file" accept=".html"/>

Upvotes: 2

Related Questions