HTML 页面中的目录选择器 [英] Directory Chooser in HTML page
问题描述
如何在 html 页面中创建目录选择器.
如果我使用输入文件元素,我只能选择文件,但我需要选择目录.
我需要这样做,因为用户应该在他的计算机中选择正确的路径.
有什么解决办法吗?
How can I create a directory chooser in html page.
If I use input file element I can select file only, but I need to select directory instead.
I need to do this beacause the user should select a right path inside his computer.
Any solutions ?
推荐答案
出于安全原因,无法在纯 HTML/JavaScript 中完成.
Can't be done in pure HTML/JavaScript for security reasons.
选择要上传的文件是您能做的最好的事情,即便如此,您也不会在现代浏览器中获得完整的原始路径.
Selecting a file for upload is the best you can do, and even then you won't get its full original path in modern browsers.
您可以使用 Java 或 Flash 将某些内容组合在一起(例如使用 SWFUpload 作为基础),但这需要大量工作并带来额外的兼容性问题.
You may be able to put something together using Java or Flash (e.g. using SWFUpload as a basis), but it's a lot of work and brings additional compatibility issues.
另一个想法是打开一个 iframe
显示用户的 C:
驱动器(或其他),但即使现在有可能(可能出于安全原因被阻止,还没有)t 尝试了很长时间)您的网站将无法与 iframe 通信(再次出于安全原因).
Another thought would be opening an iframe
showing the user's C:
drive (or whatever) but even if that's possible nowadays (could be blocked for security reasons, haven't tried in a long time) it will be impossible for your web site to communicate with the iframe (again for security reasons).
你需要这个做什么?
这篇关于HTML 页面中的目录选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!