You need to use the protocol file:///
(yes, it’s three bars) if you want to link to local files.
<a href="file:///C:\Programs\sort.mw"> Link 1 </a>
<a href="file:///C:\Videos\lecture.mp4"> Link 2 </a>
These will never open the file in your local applications automatically.
That’s for security reasons, and I’ll get to that at last
section. If it opens, it will only open in the browser. If your
browser can display the file, it will. If you can’t, probably
will ask if you want to download.
Some browsers, such as modern versions of Chrome, refuse to
go from http protocol to file protocol. Therefore, it is
better open this file locally using the file protocol,
if you want to do these things.
Why does he get stuck without file: ///
?
The first part of a URL is the protocol. A protocol is a few letters, then two dots and two bars. HTTP://
and FTP://
are valid protocols; C:/
it’s not and I’m sure it’s not even
looks like a.
C:/
is also not a valid web address. The browser can
assume that he must be http://c/
with a blank door
specified, but this will fail.
Your browser may not assume that you are referring to a file
site. There are few reasons to make this assumption because the sites
public generally do not try to link to local archives of
people.
So if you want to access local files: tell to use the
file protocol.
Why three bars?
Because it’s part of the scheme URI of the archive. You have the option of
specify a host after the first two bars. If you ignore the
specification of a host, it will only assume that you are if
referring to a file on your own PC. In other words: file:///C:/
etc is a shortcut to file:// localhost/C:/etc
.
These files will still open in your browser and that’s good
Your browser will respond to these files in the same way as they
responded to the same file anywhere on the Internet. These
files will not be opened in its standard file handler
(for example, MS Word or VLC Media Player), and you will not be able
do nothing like ask File Explorer to open the location of
filing cabinet.
This is extremely good for your safety.
Sites in your browser cannot interact with your system
very well operational. If a good site could say.mp4 lecture to
open in VLC.exe, a malicious website could tell you to
open virus.bat on CMD.exe. Or you can just tell your PC to
run some Uninstall.exe files, or open the File explorer one
million times.
This may not be convenient for you, but HTML and security
browser is not really designed for what you are doing. If
you want to open Lecture.mp4 on VLC.exe, consider writing a
desktop app.
Hello Reinaldo, notice that I want to open the link with a local application. Example an Excel file, I want to create a link that will open that file with Excel itself already installed on PC, do not want to upload documents.
– jsantos1991
I understand, and you are already doing as you should, "file:///C: 1 2 3 file.xlsx". The issue now is the security of browsers, Nowadays browsers try to block the interaction with the operating system.
– res
This link (in English) explains in detail why the browser will not let you open an xlsx as if it were a shortcut to microsoft excel, for example. https://stackoverflow.com/a/18246357/9691138
– res