Html 使用 Chrome 打开本地文件(file://)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28724751/
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-29 03:35:41  来源:igfitidea点击:

Open local files(file://) using Chrome

htmlgoogle-chrome

提问by sergio089

I have an page with some forms. All the links work fine in IE. They open in a new tab nicely when the hyperlink is click by the user; however, I realized that when Chrome is use the link doesn't open. I keep clicking but nothing opens. The only way of opening the file is copying the hyperlink, opening a new tab in Chrome, paste and go.

我有一个包含一些表格的页面。所有链接在 IE 中都可以正常工作。当用户单击超链接时,它们会在新选项卡中很好地打开;但是,我意识到当使用 Chrome 时,链接不会打开。我一直点击但没有打开。打开文件的唯一方法是复制超链接,在 Chrome 中打开一个新选项卡,粘贴并运行。

<a href="FILE:\outsideserver\files\shared\form1.pdf" target="_blank">Form1</a>

Is this something that browser do? Because I tried it with FireFox and doesn't work either? It there a way of going around? without installing anything in the browser? Because my user loves Chrome. Thank you in advanced for the responses.

这是浏览器的功能吗?因为我用 FireFox 试过它也不起作用?它有办法绕过吗?无需在浏览器中安装任何东西?因为我的用户喜欢 Chrome。预先感谢您的答复。

采纳答案by ppascualv

You can't access to files outside your server or "SandBox", sandbox include the files that user push to the browser or to your server.

您无法访问服务器或“沙箱”之外的文件,沙箱包含用户推送到浏览器或服务器的文件。

If the access from browser to a pc files from web pages was possible, it would be a security problem.

如果可以从浏览器访问网页中的 pc 文件,这将是一个安全问题。

回答by dwkd

The answer is that you can't with your approach and more importantly you shouldn't. Chrome behavior is in fact the right behavior and it protects you from having malicious users and/or scripts accessing your local resources.

答案是你不能用你的方法,更重要的是你不应该。Chrome 行为实际上是正确的行为,它可以防止恶意用户和/或脚本访问您的本地资源。

The FILEprotocol will access local or defined network namedresources which will not be available to a remote user that visits the same page. In other words, you may have outsideservermapped as a network resource/drive but someone else will not (This does not apply to IPs)

FILE协议将访问本地或定义的网络命名资源,访问同一页面的远程用户将无法访问这些资源。换句话说,您可能已outsideserver映射为网络资源/驱动器,但其他人不会(这不适用于 IP)

Here's what you can do:

您可以执行以下操作:

  • 将代码移动到服务器端脚本(php、asp 等)并将文件流式传输回来。在这里找到了一个关于 SO 的快速示例。虽然我没有验证。使用 PHP 流式传输大文件
  • 在上安装网络服务器outsideserver并将新站点映射到该shared文件夹。然后您可以通过 http ( http://outsideserver.com/form1.pdf)引用它