Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

href="file://" doesn't work

Tags:

html

file

href

I have a problem with: href="file://" Well I want to point a link in html to file, in browser if I write like

 file:///K:/filename.pdf

It works to open a file, but if I point it to:

      href="http://file:///K:/AmberCRO%20SOP/2011-07-05/SOP-SOP-3.0.pdf" 

It doesn't work. link is changed to:

file///K:/AmberCRO%20SOP/2011-07-05/SOP-SOP-3.0.pdf

The colon after file disappears. Any suggestions as to what to do?

like image 549
Sangsom Avatar asked Oct 11 '12 10:10

Sangsom


1 Answers

The reason your URL is being rewritten to file///K:/AmberCRO%20SOP/2011-07-05/SOP-SOP-3.0.pdf is because you specified http://file://

The http:// at the beginning is the protocol being used, and your browser is stripping out the second colon (:) because it is invalid.

Note

If you link to something like

<a href="file:///K:/yourfile.pdf">yourfile.pdf</a>

The above represents a link to a file called k:/yourfile.pdf on the k: drive on the machine on which you are viewing the URL.

You can do this, for example the below creates a link to C:\temp\test.pdf

<a href="file:///C:/Temp/test.pdf">test.pdf</a>

By specifying file:// you are indicating that this is a local resource. This resource is NOT on the internet.

Most people do not have a K:/ drive.

But, if this is what you are trying to achieve, that's fine, but this is not how a "typical" link on a web page works, and you shouldn't being doing this unless everyone who is going to access your link has access to the (same?) K:/drive (this might be the case with a shared network drive).

You could try

<a href="file:///K:/AmberCRO-SOP/2011-07-05/SOP-SOP-3.0.pdf">test.pdf</a>
<a href="AmberCRO-SOP/2011-07-05/SOP-SOP-3.0.pdf">test.pdf</a>
<a href="2011-07-05/SOP-SOP-3.0.pdf">test.pdf</a>

Note that http://file:///K:/AmberCRO%20SOP/2011-07-05/SOP-SOP-3.0.pdf is a malformed

like image 156
Ian G Avatar answered Oct 20 '22 01:10

Ian G