Link to home
Start Free TrialLog in
Avatar of Mike Kristensen
Mike Kristensen

asked on

Local link in hyperlink

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
Avatar of Mike Kristensen
Mike Kristensen

ASKER

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
"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.
Avatar of Julian Hansen
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.
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
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

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.
what browser are you using?
Do you get any different results using different browsers?
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.
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.
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.
ASKER CERTIFIED SOLUTION
Avatar of Mike Kristensen
Mike Kristensen

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
I didnt do anything about it.