How to open local file from browser?

后端 未结 5 776
走了就别回头了
走了就别回头了 2020-12-12 03:56

I\'m using the following when trying to open a local file:

some document&l         


        
相关标签:
5条回答
  • 2020-12-12 04:38

    This might not be what you're trying to do, but someone out there may find it helpful:

    If you want to share a link (by email for example) to a network file you can do so like this:

    file:///Volumes/SomeNetworkFolder/Path/To/file.html

    This however also requires that the recipient connects to the network folder in finder --- in menu bar,

    Go > Connect to Server

    enter server address (e.g. file.yourdomain.com - "SomeNetworkFolder" will be inside this directory) and click Connect. Now the link above should work.

    0 讨论(0)
  • 2020-12-12 04:46

    You can only open some types of files in browsers, like html css js and mp4, otherwise the browser will want to download it. Also remember that browsers replace spaces with %20. I recommend right clicking the file and opening it with chrome then copy that link and using it.

    You can open files that are local as long as it is a file that is on the file that is trying to open another file is local.

    0 讨论(0)
  • 2020-12-12 04:49

    The File API in HTML 5 now allows you to work with local files directly from JS (after basic user interaction in selecting the file(s), for security).

    From the Mozilla File API docs:

    "The File interface provides information about files and allows JavaScript in a web page to access their content.
    File objects are generally retrieved from a FileList object returned as a result of a user selecting files using the <input> element, from a drag and drop operation's DataTransfer object, or from the mozGetAsFile() API on an HTMLCanvasElement."

    For more info and code examples, see the sample demo linked from the same article.

    0 讨论(0)
  • 2020-12-12 04:54

    You cannot open local files on the client. This would be a huge security risk.

    You can link to files on your server (like you did) or you can ask the client for a file using <input type="file">

    0 讨论(0)
  • 2020-12-12 05:00

    Your issue is likely the space in the document name. Try this instead:

    <a href="file:///Users/username/Dropbox/Documents/a/some%20document.numbers">some document</a>

    The %20 will be read by your browser as a space.

    Update
    The other answer points out something I missed. The .numbers extension will not be able to be opened directly by your browser. Additionally the other answer describes the security risk this could create.

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