Home >Web Front-end >JS Tutorial >How to Open Local Directories as Hyperlinks?

How to Open Local Directories as Hyperlinks?

Barbara Streisand
Barbara StreisandOriginal
2024-10-22 10:48:02417browse

How to Open Local Directories as Hyperlinks?

Navigating Local Directories via Hyperlink

While attempting to initiate a local directory view upon link interaction, you may encounter limitations. However, there is a solution that addresses this issue and works seamlessly across various browsers.

Implementation Methodology

Since direct path opening or explorer launch from an HTML page is restricted for security reasons, a more feasible approach involves providing a downloadable link (.URL or .LNK).

Recommended Path: .URL

.URL files, being text-based, are dynamically generatable. To implement this solution:

  1. Ensure that your web server supports the .url MIME type.
  2. Craft a .url file with the following content:
<code class="txt">[InternetShortcut]
URL=file:///D:</code>
  1. Provide a link to either the dynamically generated .url script or the .url file itself in your HTML:

    <code class="html"><a href="URIShortcut.url">Round-About Linking</a></code>

Browser-Specific Behavior

  • Chrome: Prompts download of file.url, then opens it. This behavior can be optimized by enabling "Always open files of this type."
  • Firefox: Similar to Chrome, file.url is downloaded and subsequently opened.
  • Internet Explorer: No need to save a shortcut; clicking "Open" directly accesses the specified directory.

The above is the detailed content of How to Open Local Directories as Hyperlinks?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn