66

Just a basic html link question.

I have an intranet setup, and I need to link to some network drives. They are located on drives such as \server_drive\blahblah\doc.docx

Using file:// does not work on either IE8 or Firefox. How can I link to these files?

Doug
  • 1,316
  • 6
  • 19
  • 36

3 Answers3

105

To link to a UNC path from an HTML document, use file:///// (yes, that's five slashes).

file://///server/path/to/file.txt

Note that this is most useful in IE and Outlook/Word. It won't work in Chrome or Firefox, intentionally - the link will fail silently. Some words from the Mozilla team:

For security purposes, Mozilla applications block links to local files (and directories) from remote files.

And less directly, from Google:

Firefox and Chrome doesn't open "file://" links from pages that originated from outside the local machine. This is a design decision made by those browsers to improve security.

The Mozilla article includes a set of client settings you can use to override this behavior in Firefox, and there are extensions for both browsers to override this restriction.

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
  • 7
    Microsoft say that the five-slash thing is wrong. Instead your example should be "file://server/path/to/file.txt". Link: https://blogs.msdn.microsoft.com/ie/2006/12/06/file-uris-in-windows/ – Lucian Wischik Jun 13 '17 at 16:12
  • 1
    2020 here: on my Windows 10 machine, both forms (5 slashes or 2 slashes before `server`) work. (And with "work" I mean that I can copy & paste the link url to an explorer window, press Enter and the target file opens. Not that local links are clickable.) – ojdo Mar 26 '20 at 08:54
  • Updated extension links for [Chrome](https://chrome.google.com/webstore/detail/enable-local-file-links/nikfmfgobenbhmocjaaboihbeocackld/related?hl=en) and [Firefox](https://addons.mozilla.org/en-GB/firefox/addon/local-filesystem-links/). – Adam Dempsey Aug 12 '21 at 11:07
5

Setup IIS on the network server and change the path to http://server/path/to/file.txt

EDIT: Make sure you enable directory browsing in IIS

bryanbcook
  • 16,210
  • 2
  • 40
  • 69
  • I have similar issue. When you say change the path, is this is in a virtual directory? When I try to access my share using `http`, I get a 404, but if I use file://///server/path/to/file.txt in the browser, it works. I need to have http access as this link will be rendered via markdown. I have enabled directory browsing on the server. The Physical Path under Advanced Settings is pointing to the share. – DBS Oct 17 '16 at 22:53
  • When I wrote this answer, my suggestion was to put IIS on the network server and then change the URL of your content to point to the web server. You can also configure IIS to have virtual directories that map to network shares, but there are permissions between IIS and the network share to consider. – bryanbcook Oct 20 '16 at 16:42
2

Alternative (Insert tooltip to user):

<style>
    a.tooltips {
        position: relative;
        display: inline;
    }
    a.tooltips span {
        position: absolute;
        width: 240px;
        color: #FFFFFF;
        background: #000000;
        height: 30px;
        line-height: 30px;
        text-align: center;
        visibility: hidden;
        border-radius: 6px;
    }
    a.tooltips span:after {
        content: '';
        position: absolute;
        top: 100%;
        left: 50%;
        margin-left: -8px;
        width: 0;
        height: 0;
        border-top: 8px solid #000000;
        border-right: 8px solid transparent;
        border-left: 8px solid transparent;
    }
    a:hover.tooltips span {
        visibility: visible;
        opacity: 0.8;
        bottom: 30px;
        left: 50%;
        margin-left: -76px;
        z-index: 999;
    }
</style>
<a class="tooltips" href="#">\\server\share\docs<span>Copy link and open in Explorer</span></a>
spottedmahn
  • 14,823
  • 13
  • 108
  • 178
leus
  • 99
  • 4