问题描述
如何在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将东西放在一起(例如使用作为基础),但这是很多工作,并带来额外的兼容性问题。
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:
驱动器(或任何),但即使现在可能(可能会被阻止安全的原因,还没有尝试过很长一段时间),您的网站将无法与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页面中的目录选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!