JS: Submit HTML file and place file code within div

人走茶凉 提交于 2019-12-24 21:53:25

问题


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?


回答1:


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"/>


来源:https://stackoverflow.com/questions/27154409/js-submit-html-file-and-place-file-code-within-div

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!