Html Firefox 中 href="file://///..." 的解决方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5317834/
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
Workaround for href="file://///..." in Firefox
提问by hmqcnoesy
On an intranet site, let's say I want to link to a file on a share using UNC, at:
在 Intranet 站点上,假设我想使用 UNC 链接到共享上的文件,地址为:
\servername\foldername\filename.rtf
It seems the correct way to do this is with markup like this:
似乎正确的方法是使用这样的标记:
<a href="file://///servername/foldername/filename.rtf">filename.rtf</a>
That's five slashes - two for the protocol, one to indicate the root of the file system, then two more to indicate the start of the server name.
那是五个斜杠 - 两个用于协议,一个表示文件系统的根,然后另外两个表示服务器名称的开头。
This works fine in IE7, but in Firefox 3.6 it will only work if the html is from a local file. I can't get it to work when the file comes from a web server. The link is "dead" - clicking on it does nothing.
这在 IE7 中工作正常,但在 Firefox 3.6 中,只有当 html 来自本地文件时才有效。当文件来自网络服务器时,我无法让它工作。该链接是“死的”——点击它什么也不做。
Is there a workaround for this in Firefox? Those two browsers should be all I need to worry about for now.
在 Firefox 中是否有解决方法?这两个浏览器应该是我现在需要担心的全部。
Since this is obviously a feature of Firefox, not a bug, can someone explain what the benefit is to preventing this type of link?
由于这显然是 Firefox 的一个功能,而不是一个错误,有人可以解释阻止这种类型的链接有什么好处吗?
采纳答案by kbrimington
As it turns out, I was unaware that Firefox had this limitation/feature. I can sympathize with the feature, as it prevents a user from unwittingly accessing the local file system. Fortunately, there are useful alternatives that can provide a similar user experience while sticking to the HTTP protocol.
事实证明,我不知道 Firefox 有这个限制/功能。我可以同情这个功能,因为它可以防止用户无意中访问本地文件系统。幸运的是,有一些有用的替代方案可以在坚持 HTTP 协议的同时提供类似的用户体验。
One alternative to accessing content via UNC paths is to publish your content using the WebDAVprotocol. Some content managements systems, such as MS SharePoint, use WebDAV to provide access to documents and pages. As far as the end-user experience is concerned, it looks and feels just like accessing network files with a UNC path; however, all file interactions are performed over HTTP.
通过 UNC 路径访问内容的一种替代方法是使用WebDAV协议发布您的内容。某些内容管理系统(例如 MS SharePoint)使用 WebDAV 来提供对文档和页面的访问。就最终用户体验而言,它的外观和感觉就像使用 UNC 路径访问网络文件一样;但是,所有文件交互都是通过 HTTP 执行的。
It might require a modest change in your file access philosophy, so I suggest you read about the WebDAV protocol, configuration, and permission management as it relates to your specific server technology.
它可能需要对您的文件访问理念进行适度的更改,因此我建议您阅读有关 WebDAV 协议、配置和权限管理的内容,因为它与您的特定服务器技术相关。
Here are a few links that may be helpful if you are interested in learning more about configuring and using WebDAV on a few leading HTTP servers:
如果您有兴趣了解有关在几个领先的 HTTP 服务器上配置和使用 WebDAV 的更多信息,这里有一些链接可能会有所帮助:
回答by hmqcnoesy
This question has been asked at least twice before, but I was unable to find those posts before posting my own (sorry):
这个问题之前至少被问过两次,但在发布我自己的帖子之前我找不到这些帖子(抱歉):
Open a direct file on the hard drive from firefox (file:///)
从 Firefox (file:///) 打开硬盘驱动器上的直接文件
Firefox Links to local or network pages do not work
Here is a summary of answers from all three posts:
以下是所有三个帖子的答案摘要:
- Use WebDAV — this is the best solution for me, although much more involved than I had anticipated.
- Use
http://
instead offile://///
— this will serve up a copy of the document that the user cannot edit and save. - Edit user.js on the client as described here — this worked for me in Firefox 3.6.15, but without access to client machines, it's not a solution.
- In Firefox, use about:config, change the
Security.fileuri.strict_origin_policy
setting to false — this doesn't work for me in 3.6.15. Other users on [SO] have also reported that it doesn't work. - Use the locallinksFirefox extension — this sets the
Security.fileuri.strict_origin_policy
to true for you, and appears to have no other effect. - Read the file server-side and send it as the response — this presents the same problem as simply configuring your web server to use
http://
.
- 使用 WebDAV——这对我来说是最好的解决方案,尽管比我预期的要复杂得多。
- 使用
http://
代替file://///
- 这将提供用户无法编辑和保存的文档副本。 - 按照此处所述在客户端上编辑 user.js — 这在 Firefox 3.6.15 中对我有用,但无法访问客户端计算机,这不是解决方案。
- 在 Firefox 中,使用about:config,将
Security.fileuri.strict_origin_policy
设置更改为 false — 这在 3.6.15 中对我不起作用。[SO] 上的其他用户也报告说它不起作用。 - 使用locallinksFirefox 扩展——这
Security.fileuri.strict_origin_policy
对你来说设置为 true,并且似乎没有其他效果。 - 读取文件服务器端并将其作为响应发送——这与简单地配置您的 Web 服务器以使用
http://
.
回答by BalusC
Browsers like Firefox refuse to open the file:// link when the parent HTML page itself is served using a different protocol like http://.
当父 HTML 页面本身使用不同的协议(如 http://)提供服务时,Firefox 等浏览器拒绝打开 file:// 链接。
Your best bet is to configure your webserver to provide the network mapped file as a web resource so that it can be accessed by http:// from the same server instead of by file://.
最好的办法是配置您的网络服务器以提供网络映射文件作为网络资源,以便可以从同一服务器通过 http:// 而不是通过 file:// 访问它。
Since it's unclear which webserver you're using, I can't go in detail as to how to achieve this.
由于不清楚您使用的是哪个网络服务器,因此我无法详细说明如何实现这一点。
回答by Rukicc
In Firefox to Open File:\\\\\yourFileServer\docs\doc.txt
for example you need to turn on some options in Firefox configuration:
File:\\\\\yourFileServer\docs\doc.txt
例如,在 Firefox to Open 中,您需要在 Firefox 配置中打开一些选项:
user_pref("capability.policy.policynames", "localfilelinks");
user_pref("capability.policy.localfilelinks.sites", "http://yourServer1.companyname.com http://yourServer2.companyname.com");
user_pref("capability.policy.localfilelinks.checkloaduri.enabled", "allAccess");
回答by flavio.donze
Add your own policy, open configuration "about:config" in the location bar and add three new entries:
添加您自己的策略,在地址栏中打开配置“ about:config”并添加三个新条目:
- capability.policy.policynames MyPolicy
- capability.policy.MyPolicy.sites http://localhost
- capability.policy.MyPolicy.checkloaduri.enabled allAccess
- capability.policy.policynames MyPolicy
- 能力.政策。MyPolicy.sites http://localhost
- 能力.政策。MyPolicy.checkloaduri.enabled allAccess
Replace http://localhostwith your website.
Works with Firefox 70.0.
将http://localhost替换为您的网站。
适用于 Firefox 70.0。
回答by Brian D
I don't know if this will work, but give it a shot! Old article, but potentially still useful.
我不知道这是否有效,但试一试!旧文章,但可能仍然有用。
http://www.techlifeweb.com/firefox/2006/07/how-to-open-file-links-in-firefox-15.html
http://www.techlifeweb.com/firefox/2006/07/how-to-open-file-links-in-firefox-15.html