Html 如何在Javascript中使用默认目录打开文件浏览器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17420595/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to open a file browser with default directory in Javascript?
提问by ldlchina
I want to open a file browser in JavaScript and set a default directory to this file browser. For example, I will like to set the default directory to "C:\My Documents".
我想用 JavaScript 打开一个文件浏览器,并为这个文件浏览器设置一个默认目录。例如,我想将默认目录设置为“C:\My Documents”。
How to set a default directory?
It's better to use <input type="file"/>
, other controls are ok too.
如何设置默认目录?最好用<input type="file"/>
,其他控件也可以。
回答by casraf
This is impossible, as it is a security risk to let website code set any value on the machine.
这是不可能的,因为让网站代码在机器上设置任何值都存在安全风险。
Also, you can never be sure that directory exists.
What if I'm on a Mac? My stuff are in ~/Pictures
. What if I installed Windows on D:\
?
此外,您永远无法确定该目录是否存在。如果我在 Mac 上怎么办?我的东西在~/Pictures
。如果我安装了 Windows 会D:\
怎样?
回答by user2099484
<input type="file" value="YourDefaultPathAndFilename.AndExtension">
<input type="file" value="YourDefaultPathAndFilename.AndExtension">