【问题标题】:HTML: How to use Browse [input type="file"] and retrieve selected directory in Javascript?HTML:如何使用 Browse [input type="file"] 并在 Javascript 中检索所选目录?
【发布时间】:2023-03-21 10:04:02
【问题描述】:

获取所选目录的“C:/fakepath”。所以任何人都可以帮我获取选定的目录。

var dialogElement = document.createElement('dialog');
dialogElement.style.width = '80vw';
dialogElement.style.height = '30vh';
dialogElement.setAttribute("id", "test");

document.getElementById('ExportIntermediateForm').appendChild(dialogElement);

$('dialog').html(
    `<label>Select Directory</label>
     <input type="file" id="directorySelector" onchange="FilePath()" webkitdirectory directory multiple />
     <p id="path"></p>`
);


dialogElement.showModal();

function FilePath() {
     console.log("Here I need selected directory");
}

【问题讨论】:

  • 发帖前请搜索您的问题stackoverflow.com/questions/4851595/…
  • 是的。但它没有解决。完成浏览后,我需要在 javascript 中打开本地目录。
  • 您阅读链接了吗? “某些浏览器具有防止 JavaScript 知道您文件的本地完整路径的安全功能。”
  • 是的。但是我怎样才能通过其他方式实现呢?请帮帮我。
  • 阅读主题!您要么使用document.getElementById("file-id").files[0].path,如果这不起作用,那么您的浏览器不支持它并且无法完成

标签: javascript html file input electron


【解决方案1】:

您可以为此使用电子窗口。如果使用电子窗口对话框,则可以直接使用输入类型文件获取路径。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-19
    • 2011-04-01
    • 1970-01-01
    • 2011-10-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-23
    相关资源
    最近更新 更多