首页 > 解决方案 > 在存在 HTML 的同一文件夹中创建新的 html 文件

问题描述

我希望在存在 HTML 的同一文件夹中创建新的 html 文件。请帮我。我搜索了很多,没有运气

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


标签: javascripthtml

解决方案


使用后端服务器。因为 HTML 页面和脚本是在客户端执行的。在浏览器中加载页面时,您无法真正在客户端创建文件。

反过来,您也不希望客户端在服务器上创建任意文件。它会带来很大的安全风险,并可能导致可能的远程代码执行 (RCE)。


推荐阅读