最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - How to open a file browser with default directory in Javascript? - Stack Overflow

programmeradmin6浏览0评论

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".

How to set a default directory? It's better to use <input type="file"/>, other controls are ok too.

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".

How to set a default directory? It's better to use <input type="file"/>, other controls are ok too.

Share Improve this question edited Jul 2, 2013 at 8:14 George 36.8k9 gold badges69 silver badges109 bronze badges asked Jul 2, 2013 at 8:13 ldlchinaldlchina 9552 gold badges12 silver badges31 bronze badges 4
  • possible duplicate of control the working directory for <input type="file">? – mortb Commented Jul 2, 2013 at 8:17
  • I don't think it is possible. How users with a non-windows OS would use it? And think about the security risk of accessing user's filesystem. – Michael Sazonov Commented Jul 2, 2013 at 8:18
  • I'm currently not sure if it is possible to define a certain location in html5 like images, documents or movies as default. But even if it is now possible, defining a whole path like C:\My Documents (i hope it is not possible) would not make much sens, because the path could change from system to system. – t.niese Commented Jul 2, 2013 at 8:20
  • My requirement is not limit to <input type="file"/>, others are fine for me if it doesn't support to specify default directory. It's fine if can set images, documents or movies (specific folders) as default. – ldlchina Commented Jul 2, 2013 at 8:30
Add a comment  | 

2 Answers 2

Reset to default 21

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:\?

From http://www.pcreview.co.uk/threads/automatically-put-a-default-filename-in-input-type-file-value.2192852/

<input type="file" value="YourDefaultPathAndFilename.AndExtension">

发布评论

评论列表(0)

  1. 暂无评论