How to Open a File Browser with Default Directory in JavaScript

How to open a file browser with default directory in Javascript?

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

Open File dialog default folder location

You can not access client file system by Javascript because of security reasons. The browser will open the path which it decide it should open (usually last path). If you really want to do that you should use plugins such as Adobe Flash or Silverlight which gives the client to access the file system.

How Can I Open My File explorer using HTML / JS

You can't open application with javascript pure , Because they are on the front-end side .

I have two ideas for this

One use the input:file tag:

<input type="file" />​

Two, use your local network path:

window.open("file:///" + yourLocalOrNetworkPath);

file browser with specific path

This is not possible due to security reasons, some browsers do not allow you to even know the local file's path, let alone set it.

Some browsers have a security feature that prevents javascript from
knowing your file's local full path. It makes sense - as a client, you
don't want the server to know your local machine's filesystem. It
would be nice if all browsers did this.
https://stackoverflow.com/a/4851614/1817690

Open Windows Explorer from Javascript

Figured it out... Simply run shell script on your JS code!
Node.js

var exec = require('child_process').exec, child;

var isWin = /^win/.test(process.platform); // possible outcomes -> 'darwin', 'freebsd', 'linux', 'sunos' or 'win32'

exec((isWin?'start ':'open ') + name,
function (error, stdout, stderr) {
if (error !== null) {
console.log('exec error: ' + error);
}
}
);


Related Topics



Leave a reply



Submit