Skip to content Skip to sidebar Skip to footer

Open A File With Its Default Programme

In my application I want to open some files with the correct default programmes, like .doc file should be open with WORD and .psd files should be opened with Photoshop if it is ins

Solution 1:

There is no way for you to choose which application will be used to open your files with javascript...It just doesn't have that power.

Solution 2:

I don't think this is possible in JavaScript without using any activeX or something like that. Js has no access to locally installed applications.

Solution 3:

Browsers typically don't have access to the computer's filesystem for security reasons. If you know the exact path to a file you can point the browser at it using a file: URI, e.g.

file:///C:/path/to/file.ext

You may also be able to do this with a plugin, eg ActiveX, however I am unsure as to what security measures that would have.

Solution 4:

Invoke the system command 'open'. Works on Windows and Unix based clients.

Depending on where your script runs, you might not be able to invoke system commands though, for instance in a browser sandbox.

Solution 5:

If you provide a link to a file on the local file system (eg: <a href="file:///C:/mydoc.doc">) then the browser will open it - however this is not a great way to do it since the browser will first show a dialog ("Do you wish to Save or Open") and then it will "download" it into temporary files as it would if the file were remote. In this case, if you edit and save the file, it'll be the version now in your temp folder. This might not be a problem if your files are read-only, but generally it's not a great user experience.

The only other method is to use ActiveX, which is actually rather easy (though I don't have the exact code on me now - write a comment if you're interested in a snippet and I'll update). Of course this comes with the giant flashing caveats of:

  1. It only works in Internet Explorer.
  2. You need the user to fiddle with their security settings for the ActiveX scripts to run.

Post a Comment for "Open A File With Its Default Programme"