在 Intranet 站点上,假设我想使用 UNC 链接到共享上的文件,位于:
\\servername\foldername\filename.rtf
似乎正确的方法是使用如下标记:
<a href="file://///servername/foldername/filename.rtf">filename.rtf</a>
这是五个斜杠 - 两个用于协议,一个表示根文件系统的名称,然后还有两个表示服务器名称的开头。
这在 IE7 中工作正常,但在 Firefox 3.6 中只有当 html 来自本地文件时才有效。当文件来自网络服务器时我无法让它工作。该链接已“失效” - 单击它不会执行任何操作。
Firefox 中有解决此问题的方法吗?我现在只需要担心这两个浏览器。
由于这显然是 Firefox 的一个功能,而不是一个错误,有人可以解释一下阻止这种类型的链接有什么好处吗?
On an intranet site, let's say I want to link to a file on a share using UNC, at:
\\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.
Is there a workaround for this in Firefox? Those two browsers should be all I need to worry about for now.
Since this is obviously a feature of Firefox, not a bug, can someone explain what the benefit is to preventing this type of link?
发布评论
评论(6)
当父 HTML 页面本身使用不同的协议(如 http://)提供服务时,Firefox 等浏览器拒绝打开 file:// 链接。
最好的办法是配置您的 Web 服务器以将网络映射文件作为 Web 资源提供,以便可以通过 http:// 从同一服务器访问它,而不是通过 file:// 进行访问。
由于不清楚您正在使用哪个网络服务器,因此我无法详细说明如何实现这一点。
Browsers like Firefox refuse to open the file:// link when the parent HTML page itself is served using a different protocol like http://.
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://.
Since it's unclear which webserver you're using, I can't go in detail as to how to achieve this.
例如,在 Firefox 中要打开
File:\\\\\yourFileServer\docs\doc.txt
,您需要在 Firefox 配置中打开一些选项:In Firefox to Open
File:\\\\\yourFileServer\docs\doc.txt
for example you need to turn on some options in Firefox configuration:事实证明,我不知道 Firefox 有这个限制/功能。我可以理解这个功能,因为它可以防止用户无意中访问本地文件系统。幸运的是,有一些有用的替代方案可以在坚持 HTTP 协议的同时提供类似的用户体验。
通过 UNC 路径访问内容的一种替代方法是使用 WebDAV 协议发布内容。某些内容管理系统(例如 MS SharePoint)使用 WebDAV 提供对文档和页面的访问。就最终用户体验而言,它看起来和感觉就像使用 UNC 路径访问网络文件一样;但是,所有文件交互都是通过 HTTP 执行的。
它可能需要对您的文件访问理念进行适度的改变,因此我建议您阅读有关 WebDAV 协议、配置和权限管理的内容,因为它与您的特定服务器技术相关。
如果您有兴趣了解有关在一些领先的 HTTP 服务器上配置和使用 WebDAV 的更多信息,以下一些链接可能会有所帮助:
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.
One alternative to accessing content via UNC paths is to publish your content using the WebDAV protocol. 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.
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.
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:
添加您自己的策略,在地址栏中打开配置“about:config”并添加三个新条目:
将 http://localhost 替换为您的网站。
适用于 Firefox 70.0。
Add your own policy, open configuration "about:config" in the location bar and add three new entries:
Replace http://localhost with your website.
Works with Firefox 70.0.
我不知道这是否有效,但试一试!老文章,但可能仍然有用。
http://www .techlifeweb.com/firefox/2006/07/how-to-open-file-links-in-firefox-15.html
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
这个问题之前至少被问过两次,但在发布自己的帖子之前我无法找到这些帖子(抱歉):
打开直接文件在硬盘上从 Firefox (file:///)
Firefox 到本地或网络页面的链接不起作用
以下是所有三篇文章的答案摘要:
http://
而不是file://///
— 这将提供用户无法编辑和保存的文档副本。Security.fileuri.strict_origin_policy
设置更改为 false - 这在 3.6.15 中对我不起作用。 [SO] 上的其他用户也报告说它不起作用。Security.fileuri.strict_origin_policy
设置为 true,并且似乎没有其他效果。http://
相同的问题。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 Links to local or network pages do not work
Here is a summary of answers from all three posts:
http://
instead offile://///
— this will serve up a copy of the document that the user cannot edit and save.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.Security.fileuri.strict_origin_policy
to true for you, and appears to have no other effect.http://
.