Html 使html链接打开文件夹的方法有哪些

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/855614/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 23:44:17  来源:igfitidea点击:

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

htmldirectoryhyperlink

提问by Sebastien Lachance

I need to let users of an application open a folder by clicking a link inside a web page. The path of the folder is on the network and can be accessed from everywhere. I'm probably sure there is no easy way to do this, but maybe I'm mistaken?

我需要让应用程序的用户通过单击网页内的链接来打开文件夹。文件夹的路径在网络上,可以从任何地方访问。我可能确定没有简单的方法可以做到这一点,但也许我错了?

采纳答案by Andrew Duffy

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

是否要在 Windows 资源管理器中打开共享文件夹?您需要使用file:链接,但有一些注意事项:

  • 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) andthe 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.
  • 如果链接是转换的 UNC 路径 ( file://server/share/folder/),则 Internet Explorer 将起作用。
  • 如果链接是使用五个斜线 ( file://///server/share/folder) 的自身损坏形式并且用户已禁用对file:通过 HTTP 提供服务的页面中的链接的安全限制,则 Firefox 将正常工作。谢天谢地,IE 也接受损坏的链接形式。
  • 无法说服 Opera、Safari 和 Chromefile:在通过 HTTP 提供服务的页面中打开链接。

回答by highlycaffeinated

The URL file://[servername]/[sharename]should open an explorer window to the shared folder on the network.

该 URLfile://[servername]/[sharename]应打开一个资源管理器窗口,指向网络上的共享文件夹。

回答by lock

make sure your folder permissions are set so that a directory listing is allowed then just point your anchor to that folder using chmod 701 (that might be risky though) for example

确保您的文件夹权限设置为允许目录列表,然后只需使用 chmod 701 将您的锚点指向该文件夹(尽管这可能有风险)例如

<a href="./downloads/folder_i_want_to_display/" >Go to downloads page</a>

make sure that you have no index.html any index file on that directory

确保该目录上没有 index.html 任何索引文件

回答by Bickie

Using file:///// just doesn't work if security settings are set to even a moderate level.

如果安全设置设置为中等级别,则使用 file:///// 将不起作用。

If you just want users to be able to download/view files* located on a network or share you can set up a Virtual Directory in IIS. On the Properties tab make sure the "A share located on another computer" is selected and the "Connect as..." is an account that can see the network location.

如果您只是希望用户能够下载/查看位于网络或共享上的文件*,您可以在 IIS 中设置一个虚拟目录。在“属性”选项卡上,确保选择了“位于另一台计算机上的 A 共享”,并且“连接为...”是一个可以查看网络位置的帐户。

Link to the virtual directory from your webpage (e.g. http://yoursite/yourvirtualdir/) and this will open up a view of the directory in the web browser.

从您的网页链接到虚拟目录(例如http://yoursite/yourvirtualdir/),这将在 Web 浏览器中打开目录视图。

*You can allow write permissions on the virtual directory to allow users to add files but not tried it and assume network permissions would override this setting.

*您可以允许对虚拟目录的写权限以允许用户添加文件但未尝试并假设网络权限将覆盖此设置。

回答by luison

Does not work in Chrome, but this other answers suggests a solution via a plugin:

在 Chrome 中不起作用,但其他答案通过插件提出了一个解决方案:

Can Google Chrome open local links?

谷歌浏览器可以打开本地链接吗?

回答by Wyrmwood

You can also copy the link address and paste it in a new window to get around the security. This works in chrome and firefox but you may have to add slashes in firefox.

您还可以复制链接地址并将其粘贴到新窗口中以绕过安全性。这适用于 chrome 和 firefox,但您可能需要在 Firefox 中添加斜杠。

回答by Lucas Taulealea

A bit late to the party, but I had to solve this for myself recently, though slightly different, it might still help someone with similar circumstances to my own.

聚会有点晚,但我最近不得不自己解决这个问题,虽然略有不同,但它仍然可以帮助与我自己情况相似的人。

I'm using xampp on a laptop to run a purely local website app on windows. (A very specific environment I know). In this instance, I use a html link to a php file and run:

我在笔记本电脑上使用 xampp 在 Windows 上运行纯本地网站应用程序。(我知道一个非常具体的环境)。在这种情况下,我使用指向 php 文件的 html 链接并运行:

shell_exec('cd C:\path\to\file');
shell_exec('start .');

This opens a local Windows explorer window.

这将打开一个本地 Windows 资源管理器窗口。

回答by Nagaraja JB

Hope it will help someone someday. I was making a small POC and came across this. A button, onClick display contents of the folder. Below is the HTML,

希望有一天它会帮助某人。我正在制作一个小型 POC 并遇到了这个。一个按钮,onClick 显示文件夹的内容。下面是 HTML,

<input type=button onClick="parent.location='file:///C:/Users/' " value='Users'>