[英]new html file to be created in the same folder in which HTML is present
i want the new html file to be created in the same folder in which HTML is present.我希望在 HTML 所在的同一文件夹中创建新的 html 文件。 please help me.
请帮我。 am searching a lot, no luck
我搜索了很多,没有运气
<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>
Use a back-end server.使用后端服务器。 Because the HTML page and the scripts are executed on the client-side.
因为 HTML 页面和脚本是在客户端执行的。 You can't really create a file on the client-side while the page is loaded in a browser.
在浏览器中加载页面时,您无法真正在客户端创建文件。
The other way around, you won't want the client to create arbitrary files on the server as well.反过来,您也不希望客户端在服务器上创建任意文件。 It poses a great security risk and might lead to possible remote code execution (RCE).
它会带来很大的安全风险,并可能导致可能的远程代码执行 (RCE)。
You do not have a closing brace on your function您的 function 上没有右大括号
<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>
As for the wording of your question, if you are asking to create a new file that gets saved, then Aviv Lo's answer is what you need至于您问题的措辞,如果您要求创建一个可以保存的新文件,那么 Aviv Lo 的答案就是您所需要的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.