0

I'm trying to open a file on my local disk c: throught a link on my personal web page.

using this:

<a href="http://file:///C:/myfolder/myfile.pdf" target="_blank"> open locally </a>

on the new "_blank" page, the url bar appears like "file///C:/myfolder/myfile.pdf", the colon (:) was removed from "file:///". The local file doesn't open just because the colon is missed. What am I doing wrong? How can i fix it?

Arpit Jain
  • 1,217
  • 8
  • 27
Edgaras
  • 404
  • 2
  • 16

2 Answers2

0

Try structuring your link like this

<a href="file:///C:\myfolder\myfile.pdf">Open Locally</a>

You do not need to add the blank window conditional as it will open with what ever your default PDF viewer is.

thealexvond
  • 69
  • 1
  • 7
  • With this solution the href tag don't do nothing. It doesn't even open a new page. – Edgaras Feb 26 '20 at 16:17
  • It should not open a new page, with the removal of target="_blank". Make sure to check your file path, and this will only open a link if it is on the machine you are accessing it from. – thealexvond Feb 26 '20 at 16:22
  • simply nothing happens. verify by yourself. – Edgaras Feb 26 '20 at 16:46
0

Remove "http://"

<a href="file://C:/myfolder/myfile.pdf target="_blank"> open locally </a>

Local file protocol is "file://"

Abdurrahim
  • 2,078
  • 1
  • 17
  • 23
  • With this solution the href tag don't do nothing. It doesn't even open a new page. – Edgaras Feb 26 '20 at 16:16
  • @NelsonBustier I have tested this in both Linux and Windows and it worked all the time. In windows there is one explanation why this does not work for you is most likely you have registered something for handling PDF file types like AdobePDF or some third-party plugin like that or maybe your security settings does not allow it or maybe the path is wrong. You can try different browsers to test this, – Abdurrahim Feb 27 '20 at 00:49
  • On my pc (with W10), stills not work. Worst without the "http://", and try with a .txt file and keeps the same href="file://C:/myfolder/myfile.txt" ... – Edgaras Feb 27 '20 at 08:57