javascript - 在存在 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>
解决方案
使用后端服务器。因为 HTML 页面和脚本是在客户端执行的。在浏览器中加载页面时,您无法真正在客户端创建文件。
反过来,您也不希望客户端在服务器上创建任意文件。它会带来很大的安全风险,并可能导致可能的远程代码执行 (RCE)。
推荐阅读
- java - Java 接口方法未被覆盖
- php - 在 Laravel 查询生成器中删除不同表中链接的多个记录的最佳方法
- android - 从“其他”布局 XML 引用视图 ID 时如何使用 ViewBinding,即,不是相应的片段 XML?
- python - 带点的字典键不适用于 update()?
- c - 使用 qsort 按列从最小到最大对二维数组进行排序
- python - 是否可以仅启动和记录 bash 会话的输入?
- android - Firebase Auth Anonymous Sign 在可能的错误情况下
- python - Pyspark 中是否有类似于 re.compile 的函数可以帮助从字符串中删除模式
- laravel - 更改默认 Laravel “服务器错误”消息
- javascript - quick.db 获取消息作者的位置