通过链接打开文件

发布于 2024-12-27 18:20:30 字数 274 浏览 2 评论 0原文

是否可以通过 html 打开本地驱动器上的文件?我尝试过如下: link 与脚本位于同一地图中的文件。这有效,但它仅下载文件(我使用 mdb 文件,因此它不会像图片一样在网络浏览器中打开)。

当我链接到 ie link 或没有 file:// 时,什么也没有发生。是否可以正确链接到文件以打开它们,而不仅仅是下载它们?

提前致谢!

Is it possible to open a file on local drive via html? I tried things as:
<a href='filename.ext'>link</a> for a file in the same map as the script. This works, but it downloads the file only (i use a mdb-file so it won't open in the webbrowser like an picture).

When i link to i.e. <a href='file://c:\file.ext'>link</a> or just without file:// nothing happens. Is it possible to link correctly to the files to open them and not just download them?

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不气馁 2025-01-03 18:20:30

如果它在您的机器上,这是可能的。

您所要做的就是使用要打开的文件扩展名注册一个协议。
在您的情况下,.mdb 将是 MS Access 数据库文件。

如果您想单击浏览器中的链接并在 MS Access 中打开该文件,则必须执行以下操作:

<a href="your_protocol://c:\path\to\file.mdb">Open File</a>

然后您必须在计算机上注册“your_protocol”协议。

REGEDIT4

[HKEY_CLASSES_ROOT\your_protocol]
@="URL:your_protocol Protocol"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\your_protocol\shell]

[HKEY_CLASSES_ROOT\your_protocol\shell\open]

[HKEY_CLASSES_ROOT\your_protocol\shell\open\command]
@="\"C:\\Program Files\\Application\\program.exe\" \"%1\"" 

将“your_protocol”替换为您选择的任意名称,编辑注册表并链接您的文件,如示例中所示。

It is possible if it's on your machine.

What you have to do is register a protocol with the file extension you want to open.
In your case, .mdb would be MS Access database file.

If you want to click on a link in your browser and open the file in MS Access then you have to do the following:

<a href="your_protocol://c:\path\to\file.mdb">Open File</a>

Then you have to register "your_protocol" protocol with your computer.

REGEDIT4

[HKEY_CLASSES_ROOT\your_protocol]
@="URL:your_protocol Protocol"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\your_protocol\shell]

[HKEY_CLASSES_ROOT\your_protocol\shell\open]

[HKEY_CLASSES_ROOT\your_protocol\shell\open\command]
@="\"C:\\Program Files\\Application\\program.exe\" \"%1\"" 

Replace "your_protocol" with arbitrary name of your choosing, edit the registry and link your files like in the example.

眼波传意 2025-01-03 18:20:30

不。“打开”与“下载”涉及服务器返回的 Content-Disposition HTTP 标头。当您打开本地文件时,它不是来自网络服务器,因此您无法更改标头/它们不存在。

No. 'Open' vs 'download' concerns the Content-Disposition HTTP header, returned by the server. When you open a local file, it is not coming from a web server, so you cannot change the headers / they do not exist.

网白 2025-01-03 18:20:30

如果引用的 HTML 文档位于本地驱动器上,则相对 URL 将引用本地文件,因此例如 link 将引用以下位置的文件:同一个文件夹。但是,浏览器随后将获取指定媒体类型(例如 text/html 或 image/gif)的 HTTP 标头,因此它们需要应用一些启发式方法来猜测如何处理它,或者在系统中应用绑定,或者只是提供一个“另存为”对话框(这是浏览器在不知道或猜测媒体类型的情况下真正可以做的唯一事情)。

不过,通常情况下,只要您使用众所周知的文件名后缀(例如 .html 或 .gif),此方法就可以工作。

如果引用的文档位于服务器上,情况会有所不同,但理论上您可以使用 file: schema 引用本地文件,但其效果完全取决于系统。示例 link 在语法上是错误的(尽管某些浏览器可能接受它),因为反斜杠“\ URL 中不允许出现“”。使用 link 原则上是可行的,并且它在 Web 的早期确实有效,以防万一用户的系统碰巧有一个可以通过路径名 c:/file.ext 访问的文件(可能被系统映射到 c:\file.ext)。

但浏览器通常已经停止支持 file: 方案,大概是出于安全原因。当然,当使用 file: URL 时,不会将任何信息直接发送到任何服务器,但人们认为这可能是一种间接的安全威胁。此外,file: URL 从一开始的用处就非常有限。 (它们有时在本地网络中用于链接到不充当 HTTP 服务器的本地网络服务器上的文件。)

If the referring HTML document is on local drive, relative URLs will refer to local files, so e.g. <a href='filename.ext'>link</a> would refer to a file in the same folder. However, browsers will then get to HTTP headers that would specify the media type (such as text/html or image/gif), so they will need to apply some heuristics in guessing what to do with it, or to apply bindings in the system, or just offer a “Save As” dialog (the only thing a browser can really do without knowing or guessing the media type).

Typically, however, this will work as far as you use commonly know filename suffixes like .html or .gif.

If the referring document is on a server, things are different, but you can in theory refer to local files using the file: scheme , but its effect is completely system-dependent. The example <a href='file://c:\file.ext'>link</a> is syntactically malformed (though some browsers may accept it), since the backslash “\” is not allowed in a URL. Using <a href='file://c:/file.ext'>link</a> could in principle work, and it did work on early days of the Web, in case the user’s system happened to have a file that can be accessed with the pathname c:/file.ext (possibly mapped to c:\file.ext by the system).

But browsers have generally stopped supporting the file: scheme, presumably for assumed security reasons. Of course no information is directly sent to any server when a file: URL is used, but people thought it might be an indirect security threat. Moreover, file: URLs were of very limited usefulness from the beginning. (They were sometimes used in local networks to link to files on local network servers that do no act as HTTP servers.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文