20

I would like to make a link from a web page to a file on a local filesystem and make it work in all browsers (or at least in Internet Explorer, Firefox and Chrome).

For example, the following works in Internet Explorer:

<a href="\\myserver\doc\info.pdf">Info here</a>

but not in Firefox and Chrome.

Is there a way to make a link that works in all browsers?

Or a way to use javascript to detect which browser it is and then display the appropriate link based on the filename?

Ole Lynge
  • 4,457
  • 8
  • 43
  • 57
  • 1
    Not that this is pure conjecture, but files "downloaded" from the local file system from a network share typically have different security attributes than ones downloaded from a web server. This might thus be seen as a way to circumvent security, and might very well not be allowed at all in other browsers. – Lasse V. Karlsen Aug 10 '09 at 12:26
  • Similar question on SuperUser with more details: [How do I instruct Firefox to allow me to open file:/// URLs on a localhost-server http:// webpage?](https://superuser.com/questions/1513156/). – sleske Jan 07 '20 at 09:36

2 Answers2

20

Links to local files on pages that were retrieved via HTTP(S) are deliberately disabled in Mozilla/Firefox, because they can be a security risk, and have been used in attacks in the past.

You can override this behaviour, however. For details, see this article in MozillaZine.

sleske
  • 81,358
  • 34
  • 189
  • 227
  • Very old but anyway, since I've got an issue with this: why is this a security issue? why is it more a problem compare to download the same file via HTTP? – Rafiki Nov 24 '17 at 09:20
  • @Rafiki: The linked article lists some risks. If you want to know more, this sounds like an excellent new question. Consider asking it as such on https://security.stackexchange.com/ . – sleske Nov 24 '17 at 09:38
9

try prefixing your url with file:///

smercer
  • 916
  • 1
  • 6
  • 15
  • 3
    You'll also need to convert the back slashes to forward slashes, thus your example would be file://///myserver/doc/info.pdf. This is covered in the link sleske gave in his answer. – Cahlroisse Aug 10 '09 at 12:35