简体   繁体   English

在 HTML 所在的同一文件夹中创建新的 html 文件

[英]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.

相关问题 如何引用另一个文件夹中存在的html中的javascript文件 - How to refer javascript file in html present in another folder 为什么要创建新表,而不是在HTML文件中刷新同一表? - Why are new tables being created instead of the same one being refreshed in my HTML file? 如何使用js重定向到位于文件夹内的同一目录中的另一个html文件? - How to redirect to another html file in the same directory which is located inside a folder using js? Javascript - 读取文件(不是上传文件,但文件存在于与html文件相同的目录中) - Javascript - reading a file (not uploaded file,but file present in the same directory as the html file) 如何从同一div中存在的多个html元素动态获取值? - How to get values dynamically from multiple html elements which are present in same div? HTML无法识别同一文件夹中的JS文件 - HTML isn't recognizing the JS file in the same folder 如何在 html 文件内的节点模块文件夹中包含引导插件(输入微调器)。 - how to include a bootstrap plugin(input spinner) present in node module folder inside a html file.? 使用JavaScript和html同时显示图片和文字 - Present an image & TEXT at this same time with JavaScript and html 如何在 html 文件中声明一个全局变量,该变量可以被另一个 html 文件以及同一个项目使用 - How to declare a global variable in html file which can be used by another html file as well of same project HTML 不渲染使用 TransformerFactory 创建的 XMLDom - HTML not render XMLDom which created by using TransformerFactory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM