3

I built a CRM for a client of mine, and now they've requested an interesting feature:

For each customer record, they have a matching directory of files on their local computer. They want the ability to open that folder in Windows Explorer directly from within the web app (the app doesn't need access to the directory/files; it just has to launch Windows Explorer so that the user can interact with their files).

This is obviously not possible with regular JavaScript running in the browser (thankfully). I thought there might be some way to accomplish this by building a Chrome extension for this purpose, but it seems Chrome extensions/apps can only access a sandboxed filesystem, which doesn't serve my needs at all. Building an NPAPI plugin in out of the question since Chrome is discontinuing support for NPAPI.

File URIs don't solve this problem either. Their display is ugly, there's no drag-and-drop, no big icons/thumbnails, no sorting etc. They want the full capability of the Windows Explorer.


The only viable option I thought of is to create a local node.js server, make a localhost CORS request to that server, and then run an exec command from node.

Any better idea?

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
Joseph Silber
  • 214,931
  • 59
  • 362
  • 292

2 Answers2

3

One possibility is to register a custom URI protocol handler with the user's operating system, and then your web page can contain links using your custom protocol, such as openfolder://c/path/to/folder This sort of customization is probably most commonly seen in practice with itunes:// links.

A quick Google search led me to this decent looking tutorial: https://support.shotgunsoftware.com/hc/en-us/articles/200213756-How-to-launch-external-applications-using-custom-protocols-rock-instead-of-http-

The downside is that the user will have to run a small installer of some sort in order to set the correct registry entries (or whatever the non-Windows equivalent is for other OSes) and to drop a small script on disk. That would be much lighter-weight than running a node.js server like you proposed, though.

The linked tutorial uses a Python script, but even that is probably overkill for your needs. A batch file would likely suffice.

EDIT: One additional note, please be aware of the security implications of implementing a custom handler like this. Any webpage in any browser can potentially take advantage of your custom protocol, and an attacker would be able to pass arbitrary data to your script. You should take steps to ensure that the script will not accidentally execute arbitrary commands that may be injected by a malicious web page, and that it will only open a folder and nothing else.

David Mills
  • 2,385
  • 1
  • 22
  • 25
0

That would require each customer to run a node.js server, which seems unrealistic in your case.

You could use File URIs.

Browsers will refuse to open them by default. However, as suggested in this answer, you could ask your customers to install LocalLinks.

Community
  • 1
  • 1
Laurent Perrin
  • 14,671
  • 5
  • 50
  • 49
  • There's exactly one person using this project, so that won't be a problem. File URIs are not a solution. They want to browse their files in Windows Explorer, with nice icons and thumbnails and drag-and-drop and... – Joseph Silber Oct 02 '13 at 15:36
  • Yeah, I can open a local folder, but it stays inside Chrome. – Laurent Perrin Oct 02 '13 at 15:49