Local link in hyperlink

Mike Kristensen
Mike Kristensen used Ask the Experts™
on
Hi all

This works great in browser: file://///mediecenter/medie%20center
If i paste the above link into edge, it will open the path locally.

But if i try to put it on a website using: <p><a href="file://///mediecenter/medie%20center" target="_blank"> mediecenter</a></p>
Then it wont let me click the link.

I kinda just want it to paste "file://///mediecenter/medie%20center" into the adress bar and enter. But something goes wrong when you put file:///// into a href syntax.
What am i missing?

Best regards Mike Kristensen
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Mike KristensenIT administrator

Author

Commented:
I tried this aswell: <p><a href="file:///\\mediecenter\medie%20center" target="_blank"> mediecenter</a></p>

Still it seems that it wont accept that its a link. :S
ChrisSr. Systems Engineer

Commented:
"http" is a protocol pointing to a web resource, "file" points to a local resource - you can't use a local resource out on the internet, as \\mediacenter, isn't available externally.
You could trick it to work, if you were all on the same LAN, and specified an absolute path, but each client, would have to have local access to that path.
For example, If you link to something like

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

Open in new window


The above represents a link to a file called X:/yourfile.pdf on the X: drive on the machine on which you are viewing the URL. Each machine you want to access, would need to have an X: drive that is mapped to the location.

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

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

Open in new window


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

Best practice would be to link your files relative to your webpage. <a href="files/file.txt"> and store your file into files/ folder.
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
This is for security reasons. If you load the html file with the link into the browser using file://path/to/file then it will work.

If you load the file by getting it form a web server - it won't.

Reason: Domains are not the same - the source of the page does not match the source referred to in the link so the browser will not allow the request.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

ChrisSr. Systems Engineer

Commented:
To add on to Julian's comment,
Most newer browsers won't even support this type of linking format anymore, as they pose a security risk. Take a look at the security considerations posted under the standard.
https://tools.ietf.org/html/rfc8089

It can be done, however, you are implementing something with a fairly significant risk involved.
https://foswiki.org/Support/Faq72
Mike KristensenIT administrator

Author

Commented:
But mediecenter is a network drive. Where all clients have access.
A local NAS server, that should be accessed through the network path in Windows 10.

If i do the below, then it still wont go to that location, if it isent pasted into the address bar.
<a href="file:///\\mediecenter\medie center">yourfile.pdf</a>

Open in new window


Even if i do what Chris says, i wont be able to click the link. It is just dead and does not respond at all.
<a href="file:///X:/yourfile.pdf">yourfile.pdf</a>

Open in new window

Mike KristensenIT administrator

Author

Commented:
It is ridicules. I'm just forwarding them to there own local path. How can that make a security risk?

Its just a simple link to there own PC folder path. Its not even online.
ChrisSr. Systems Engineer

Commented:
what browser are you using?
Do you get any different results using different browsers?
Mike KristensenIT administrator

Author

Commented:
When i use Edge (Which i plan), it opens the local path system (sry i dont know this name).
This is only if i paste it to address bar.

Firefox and Chrome opens the link in the browser window. This is not the best solution, because there are different kind of file types that browsers cant open. The best thing is the Edge way, which is super perfect and a very powerful and smart solution.
Distinguished Expert 2018

Commented:
You also have to bear in mind the level of integration that Edge and Internet Explorer have with Windows, where they have access to Windows Explorer AND are only designed for Windows. IHowever, but their very nature of being cross platform and not being Microsoft products, you're not going to get Chrome or Firefox able to do things the same way.

I know you cited that this did not work:
<a href="file:///\\mediecenter\medie center">yourfile.pdf</a>

Open in new window


However, this should:
<a href="file:///\\mediecenter\medie%20center">yourfile.pdf</a>

Open in new window


The key difference is the fact that the space was encoded in the URL reference.
Mike KristensenIT administrator

Author

Commented:
True. But it wont work.

This dont work:
<a href="file:///\\mediecenter\medie%20center">yourfile.pdf</a>

Open in new window


If you paste it, it works.
If you right click a the link and add it to your reading list, then you can access it there.
But i cant click the link and make it open up the folder.
IT administrator
Commented:
The problem happens as soon as it is not locally triggered.

I assume clicking a link on a website, does not qualify as being local.
But as soon as you paste it into the address bar, then its locally triggered.
And if you add it to your local reading list in Edge, then its local as well.
ChrisSr. Systems Engineer

Commented:
Hi Mike,
Like I indicated, I believe this is a browser problem. I believe this is functionality that some browsers have already eliminated, and others are working towards eliminating.
There isn't anything wrong with how you are formatting the URL:
<a href="file:///\\mediecenter\medie%20center">yourfile.pdf</a>

Open in new window


Its that the browser is not longer supporting the ability to open local links from a webpage. I understand you can do it directly, for now.. however, I believe, they will eliminate the ability to do that as well in the near future.

The only solution I have seen that seems to work was to map a virtual directory in IIS to the networked drive with the documents, so the url became a friendly "http://" address.

Setting virtual directories:

IIS:

http://www.iis.net/configreference/system.applicationhost/sites/site/application/virtualdirectory

Apache:

http://w3shaman.com/article/creating-virtual-directory-apache
Mike KristensenIT administrator

Author

Commented:
I didnt do anything about it.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial