简体   繁体   English

HTML:如何使用浏览 [input type="file"] 并在 Javascript 中检索选定的目录?

[英]HTML: How to use Browse [input type="file"] and retrieve selected directory in Javascript?

Getting "C:/fakepath" for selected directory.为所选目录获取“C:/fakepath”。 So can anyone please help me to get the selected directory.因此,任何人都可以帮助我获取所选目录。

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");
}

You can use electron window for this.您可以为此使用电子窗口。 You can directly get path using input type file if you use electron windows dialog.如果您使用电子窗口对话框,您可以使用输入类型文件直接获取路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM