You need to use the protocol file:///
(yes, it's three slashes) 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 .
This is for security reasons, and I'll get to that in the last
section. If it opens, it will only open in the browser. If your
browser can display the file, it will. If you can not, probably
will ask if you want to download.
Some browsers, like modern versions of Chrome, refuse to
pass from the http protocol to the file protocol. Therefore, it is
best to 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 some letters, then two points and two bars. HTTP://
and FTP://
are valid protocols; C:/
is not and I'm sure not even
looks like one.
C:/
is also not a valid web address. The browser can
assume that it must be http://c/
with a blank port
specified, but this will fail.
Your browser may not assume that you are referring to a file
local. There are few reasons to make this assumption, because the websites
generally do not attempt to link to the local files of the
people.
So, if you want to access local files: say to use the
file protocol.
Why three bars?
Because it's part of the File URI scheme. You have the option to
specify a host after the first two slashes. If you ignore the
specification of a host, it will only assume that you are
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 that they
responded to the same file anywhere on the Internet. Those
files will not be opened in your default file handler
(for example, MS Word or VLC Media Player), and you can not
do nothing like asking File Explorer to open the location of the
file.
This is extremely good for your security.
Sites in your browser can not interact with your system
very well. If a good website could say talk.mp4 to
open in VLC.exe, a malicious website could tell you to
open virus.bat in 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
browser was not really designed for what you are doing. If
If you want to open lecture.mp4 in VLC.exe, consider writing a
desktop application.