【发布时间】: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