What Are the Ways to Make an HTML Link Open a Folder

What are the ways to make an html link open a folder

Do you want to open a shared folder in Windows Explorer? You need to use a file: link, but there are caveats:

  • Internet Explorer will work if the link is a converted UNC path (file://server/share/folder/).
  • Firefox will work if the link is in its own mangled form using five slashes (file://///server/share/folder) and the user has disabled the security restriction on file: links in a page served over HTTP. Thankfully IE also accepts the mangled link form.
  • Opera, Safari and Chrome can not be convinced to open a file: link in a page served over HTTP.

How to open a windows folder when clicking on some link on a HTML page using Python

Try to use URI with file: scheme like file:///C:/TestData/openfolder.html in your html:

<a href="file:///C:/TestData/openfolder.html">Link to test data</a>

Here is article on using file URIs in Windows.

UPD (extraction from comments): Each browser has its own way to handle such urls. At least Internet Explorer 8 under Windows 7 opens links in Windows Explorer as was required by jags.

Finally, for dynamic pages the web server is required. If one is needed take a look at discussion on creating simple web services using python.

How to open a local folder in explorer through a Chrome App Mode window?

you can do this in your html file

<form action="file://ip_addr/shared_folder/">
<input type="submit" value="Go to folder" />
</form>

P.S. I think you must have the network share mounted on your computer, for example if you want to access to "192.168.1.55/file" you must at least mount a folder from 192.168.1.55 with the same credential of /file

How can I create a link to a local file on a locally-run web page?

You need to use the file:/// protocol (yes, that'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. That's for security reasons which I'll cover in the last section. If it opens, it will only ever open in the browser. If your browser can display the file, it will, otherwise it will probably ask you if you want to download the file.

You cannot cross from http(s) to the file protocol

Modern versions of many browsers (e.g. Firefox and Chrome) will refuse to cross from the http(s) protocol to the file protocol to prevent malicious behaviour.

This means a webpage hosted on a website somewhere will never be able to link to files on your hard drive. You'll need to open your webpage locally using the file protocol if you want to do this stuff at all.

Why does it get stuck without file:///?

The first part of a URL is the protocol. A protocol is a few letters, then a colon and two slashes. HTTP:// and FTP:// are valid protocols; C:/ isn't and I'm pretty sure it doesn't even properly resemble one.

C:/ also isn't a valid web address. The browser could assume it's meant to be http://c/ with a blank port specified, but that's going to fail.

Your browser may not assume it's referring to a local file. It has little reason to make that assumption because webpages generally don't try to link to peoples' local files.

So if you want to access local files: tell it to use the file protocol.

Why three slashes?

Because it's part of the File URI scheme. You have the option of specifying a host after the first two slashes. If you skip specifying a host it will just assume you're referring to a file on your own PC. This means file:///C:/etc is a shortcut for file://localhost/C:/etc.

These files will still open in your browser and that is good

Your browser will respond to these files the same way they'd respond to the same file anywhere on the internet. These files will not open in your default file handler (e.g. MS Word or VLC Media Player), and you will not be able to do anything like ask File Explorer to open the file's location.

This is an extremely good thing for your security.

Sites in your browser cannot interact with your operating system very well. If a good site could tell your machine to open lecture.mp4 in VLC.exe, a malicious site could tell it to open virus.bat in CMD.exe. Or it could just tell your machine to run a few Uninstall.exe files or open File Explorer a million times.

This may not be convenient for you, but HTML and browser security weren't really designed for what you're doing. If you want to be able to open lecture.mp4 in VLC.exe consider writing a desktop application instead.

How do I link back out of a folder using the a-href tag?

Try setting your link to be your site root as so; note the / in front of home.html:

<a href="/home.html">bla</a>

Or if you know the path is definitely one directory down then just explicitly tell it to go down 1 directory; note the ../ in front of the home.html.

<a href="../home.html">bla</a>

Opening a mapped Windows Explorer folder using HTML hyperlink from Microsoft Edge

Edge requires mapped LAN locations to be specified in the UNC-format, while IE used to be more agnostic about it. For more information about UNC-paths check out this link.

<p><a href = "file:///P:\somenetworkfolder"> Some Network Folder (Only works in IE)</a></p>
<p><a href = "\\servername\path\somenetworkfolder"> Some Network Folder (Works in Edge and IE)</a></p>

Out of interest, if you want similar functionality in Chrome, you have to use an extension to grant the browser permission to open Windows Explorer. Check out the Local Explorer Chrome Extension, or write your own.

How to open Windows Explorer via link

Ok. I got it. My mistake was that I wrote whole path to the folder. That wasn't necessary. All I had to do was "file://///servername/folder3 and not "file://///servername/folder1/folder2/folder3". Thanks for all your suggestions and comments.

An URL to a Windows shared folder

I think there are two issues:

  1. You need to escape the slashes.
  2. Browser security.

Explanation:

  1. I checked one of mine, I have the pattern:

    <a href="file://///server01\fshare\dir1\dir2\dir3">useful link </a>

    Please note that we ended up with 5 slashes after the protocol (file:)

  2. Firefox will try to prevent cross site scripting. My solution was to modify prefs.js in the profile directory. You will add two lines:

    user_pref("capability.policy.localfilelinks.checkloaduri.enabled", "allAccess");
    user_pref("capability.policy.localfilelinks.sites", "http://mysite.company.org");



Related Topics



Leave a reply



Submit