How open a local file with the associated program from a web page?

前端 未结 6 1597
萌比男神i
萌比男神i 2021-01-23 23:25

I know the user of my app has a local file named c:\\sourcefile.cs, I need to find a way to render a link to that file so that when he clicks the link, it will open the file in

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

    You can use a link;

    <a href="file:///c:/sourcefile.cs">Open File</a>
    

    That should open the file with the default application.

    0 讨论(0)
  • 2021-01-23 23:37

    You should ask users of your app (since it is for internal use) to change a firefox option

    Tools -> Options -> Applications(tab)

    There they should associate the .cs with the action you want (to open the VS)..

    now using the <a href="file:///c:/sourcefile.cs"> should work..

    [update]

    Seems like firefox has removed the option to add a new mimetype..

    there is a manual workaround..

    You will need to locate the firefox profile (located at : APPDATA%\Mozilla\Firefox\Profiles\xxxxxxxx.default\ )

    and then edit the file mimeTypes.rdf

    add the following element

    <RDF:Description RDF:about="urn:mimetype:text/cs"
                       NC:value="text/cs"
                       NC:editable="true"
                       NC:fileExtensions="cs"
                       NC:description="CSharp Source File">
        <NC:handlerProp RDF:resource="urn:mimetype:handler:text/cs"/>
    </RDF:Description>
    

    and also find the existing <RDF:Seq RDF:about="urn:mimetypes:root"> and add to it the

    <RDF:li RDF:resource="urn:mimetype:text/cs"/>
    

    Now you can edit it with from the applications tab as shown earlier..

    0 讨论(0)
  • 2021-01-23 23:45

    I don't know about opening in visual studio, but this might work:

    file:///c:/sourcefile.cs
    

    It depends on browser, browser settings, and of course file associations.

    0 讨论(0)
  • 2021-01-23 23:48

    This is not possible because of security reasons. Javascript in the browser cannot access the clients computer.

    You would need to use a Java applet or something else like that to make that happen.

    0 讨论(0)
  • 2021-01-23 23:53

    You will have to use some sort of binary code (meaning, non-JavaScript) which will more than likely require explicit permission on the user's part to access the browser's hard drive.

    For FireFox, the way to do this is through a Plugin which will give the browser the capability (or at least your plugin the capability through the browser) to do what you want, while getting the explicit security permissions.

    You should start with the API for FireFox plugins and go from there. This is a FireFox-specific solution.

    If you want something that is browser-agnostic at some point, you might want to look into embedding a Java applet into the page. Of course, this will require permissions from the user for the applet to access the hard drive, but it will work in any browser that has the Java plugin installed.

    0 讨论(0)
  • 2021-01-23 23:53

    Latest firefox (3.6) maybe could help, try search "file api". Or you can use java applets.

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