open a file with its default programme

前端 未结 6 1705
旧时难觅i
旧时难觅i 2021-01-23 10:40

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

相关标签:
6条回答
  • 2021-01-23 11:12

    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.

    0 讨论(0)
  • 2021-01-23 11:14

    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.

    0 讨论(0)
  • 2021-01-23 11:26

    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.
    0 讨论(0)
  • 2021-01-23 11:31

    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.

    0 讨论(0)
  • 2021-01-23 11:31

    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.

    0 讨论(0)
  • 2021-01-23 11:31

    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.

    0 讨论(0)
提交回复
热议问题