Abhishek
Abhishek

Reputation: 997

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 installed, and this should be done under html or java script.

Please tell me how to do it.

Upvotes: 3

Views: 8119

Answers (6)

Kobi
Kobi

Reputation: 138017

JavaScript cannot run programs, but if you have a file on your server you can simply link to it:

<a href='image.psd'>Download File</a>

Users will be promped to download the file or open it using the default program (for most files). Again - as others have said - this is determined by the browser. IE can open doc files on the browsers, and PDF documents can be opened that way too.

Upvotes: 1

nickf
nickf

Reputation: 546035

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.

Upvotes: 0

psychotik
psychotik

Reputation: 39019

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.

Upvotes: 0

Tullo_x86
Tullo_x86

Reputation: 2673

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.

Upvotes: 1

rahul
rahul

Reputation: 187040

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.

Upvotes: 0

peirix
peirix

Reputation: 37741

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.

Upvotes: 1

Related Questions