如何创建一个在IE和Firefox中都有效的file://超链接?

时间:2021-06-16 07:07:18

In my documentation web pages, I often need to provide links to locations, files and applications (.xbap) stored on the intranet.

在我的文档网页中,我经常需要提供存储在Intranet上的位置,文件和应用程序(.xbap)的链接。

In IE, this works fine with URLs formatted like this:

在IE中,这适用于格式如下的URL:

<a href="file://///company.org/ProjectA/StatsReport">Go to folder</a>
<a href="file://///company.org/ProjectA/Readme.txt">Download file</a>
<a href="file://///company.org/ProjectA/Dashboard.xbap">Run xbap</a>

These links all work fine under IE, but in Firefox they don't.

这些链接在IE下都可以正常工作,但在Firefox中它们没有。

Does anyone know how I can format the above links to work both in IE and Firefox?

有谁知道如何格式化上述链接在IE和Firefox中工作?

Edit The above link actually work if I put them in a local file. They stop working only in Firefox when they are part of a html file on the network (not on my machine). There must be some kind of security setting in Firefox that prevents file:/// links from working coming from external content?

编辑如果我将它们放在本地文件中,上面的链接实际上是有效的。当它们是网络上的html文件(不在我的机器上)的一部分时,它们仅停止在Firefox中工作。 Firefox中必须有某种安全设置,以防止文件:///链接来自外部内容吗?

6 个解决方案

#1


You could check out this link, or you could try using UNC paths.

您可以查看此链接,也可以尝试使用UNC路径。

#2


just use

file:///

works in IE, Firefox and Chrome as far as I can tell.

据我所知,可以在IE,Firefox和Chrome中使用。

see http://msdn.microsoft.com/en-us/library/aa767731(VS.85).aspx for more info

有关详细信息,请参阅http://msdn.microsoft.com/en-us/library/aa767731(VS.85).aspx

#3


file Protocol
Opens a file on a local or network drive.

文件协议在本地或网络驱动器上打开文件。

Syntax

Copy
 file:///sDrives[|sFile]
Tokens 

sDrives
Specifies the local or network drive.

sDrives指定本地或网络驱动器。

sFile
Optional. Specifies the file to open. If sFile is omitted and the account accessing the drive has permission to browse the directory, a list of accessible files and directories is displayed.

sFile可选。指定要打开的文件。如果省略sFile并且访问驱动器的帐户具有浏览目录的权限,则会显示可访问文件和目录的列表。

Remarks

The file protocol and sDrives parameter can be omitted and substituted with just the command line representation of the drive letter and file location. For example, to browse the My Documents directory, the file protocol can be specified as file:///C|/My Documents/ or as C:\My Documents. In addition, a single '\' is equivalent to specifying the root directory on the primary local drive. On most computers, this is C:.

可以省略文件协议和sDrives参数,并仅使用驱动器号和文件位置的命令行表示替换。例如,要浏览My Documents目录,可以将文件协议指定为file:/// C | / My Documents /或C:\ My Documents。此外,单个'\'相当于指定主本地驱动器上的根目录。在大多数计算机上,这是C:。

Available as of Microsoft Internet Explorer 3.0 or later.

自Microsoft Internet Explorer 3.0或更高版本起可用。

Note Internet Explorer 6 Service Pack 1 (SP1) no longer allows browsing a local machine from the Internet zone. For instance, if an Internet site contains a link to a local file, Internet Explorer 6 SP1 displays a blank page when a user clicks on the link. Previous versions of Windows Internet Explorer followed the link to the local file.

注意Internet Explorer 6 Service Pack 1(SP1)不再允许从Internet区域浏览本地计算机。例如,如果Internet站点包含指向本地文件的链接,则当用户单击该链接时,Internet Explorer 6 SP1将显示空白页。以前版本的Windows Internet Explorer遵循指向本地文件的链接。

Example

The following sample demonstrates four ways to use the File protocol.

以下示例演示了使用File协议的四种方法。

Copy

//Specifying a drive and a file name. 

file:///C|/My Documents/ALetter.html

//Specifying only a drive and a path to browse the directory. 

file:///C|/My Documents/

//Specifying a drive and a directory using the command line representation of the directory location. 

C:\My Documents\

//Specifying only the directory on the local primary drive. 

\My Documents\

http://msdn.microsoft.com/en-us/library/aa767731

#4


In case someone else finds this topic while using localhost in the file URIs - Internet Explorer acts completely different if the host name is localhost or 127.0.0.1 - if you use the actual hostname, it works fine (from trusted sites/intranet zone).

如果其他人在文件URI中使用localhost时发现此主题 - 如果主机名是localhost或127.0.0.1,则Internet Explorer的行为完全不同 - 如果使用实际主机名,则它可以正常工作(来自可信站点/内部网区域)。

Another big difference between IE and FF - IE is fine with uris like file://server/share/file.txt but FF requires additional slashes file:////server/share/file.txt.

IE和FF之间的另一个很大的区别 - IE对于像文件://server/share/file.txt这样的uris很好,但FF需要额外的斜杠文件:////server/share/file.txt。

#5


Paste following link to directly under link button click event, otherwise use javascript to call code behind function

将以下链接粘贴到链接按钮单击事件下,否则使用javascript调用函数后面的代码

Protected Sub lnkOpen_Click(ByVal sender As Object, ByVal e As EventArgs) 
    System.Diagnostics.Process.Start(FilePath)
End Sub

#6


At least with Chrome, (I don't know about Firefox) You can drag the icon to the left of the URL in the browser to a folder location on your desktop and it will create a file that behaves as an internet shortcut.

至少在Chrome上,(我不知道Firefox)您可以将浏览器中URL左侧的图标拖到桌面上的文件夹位置,它将创建一个充当互联网快捷方式的文件。

I don't know if the file format is universal yet, however Chrome seems to know what to do with it.

我不知道文件格式是否具有通用性,但Chrome似乎知道如何处理它。

The file produced is a .url file and contains the following:

生成的文件是.url文件,包含以下内容:

[InternetShortcut] URL=http://www.accordingtothescriptures.org/prophecy/353prophecies.html

You can replace the URL with anything you'd like.

您可以将URL替换为您想要的任何内容。

#1


You could check out this link, or you could try using UNC paths.

您可以查看此链接,也可以尝试使用UNC路径。

#2


just use

file:///

works in IE, Firefox and Chrome as far as I can tell.

据我所知,可以在IE,Firefox和Chrome中使用。

see http://msdn.microsoft.com/en-us/library/aa767731(VS.85).aspx for more info

有关详细信息,请参阅http://msdn.microsoft.com/en-us/library/aa767731(VS.85).aspx

#3


file Protocol
Opens a file on a local or network drive.

文件协议在本地或网络驱动器上打开文件。

Syntax

Copy
 file:///sDrives[|sFile]
Tokens 

sDrives
Specifies the local or network drive.

sDrives指定本地或网络驱动器。

sFile
Optional. Specifies the file to open. If sFile is omitted and the account accessing the drive has permission to browse the directory, a list of accessible files and directories is displayed.

sFile可选。指定要打开的文件。如果省略sFile并且访问驱动器的帐户具有浏览目录的权限,则会显示可访问文件和目录的列表。

Remarks

The file protocol and sDrives parameter can be omitted and substituted with just the command line representation of the drive letter and file location. For example, to browse the My Documents directory, the file protocol can be specified as file:///C|/My Documents/ or as C:\My Documents. In addition, a single '\' is equivalent to specifying the root directory on the primary local drive. On most computers, this is C:.

可以省略文件协议和sDrives参数,并仅使用驱动器号和文件位置的命令行表示替换。例如,要浏览My Documents目录,可以将文件协议指定为file:/// C | / My Documents /或C:\ My Documents。此外,单个'\'相当于指定主本地驱动器上的根目录。在大多数计算机上,这是C:。

Available as of Microsoft Internet Explorer 3.0 or later.

自Microsoft Internet Explorer 3.0或更高版本起可用。

Note Internet Explorer 6 Service Pack 1 (SP1) no longer allows browsing a local machine from the Internet zone. For instance, if an Internet site contains a link to a local file, Internet Explorer 6 SP1 displays a blank page when a user clicks on the link. Previous versions of Windows Internet Explorer followed the link to the local file.

注意Internet Explorer 6 Service Pack 1(SP1)不再允许从Internet区域浏览本地计算机。例如,如果Internet站点包含指向本地文件的链接,则当用户单击该链接时,Internet Explorer 6 SP1将显示空白页。以前版本的Windows Internet Explorer遵循指向本地文件的链接。

Example

The following sample demonstrates four ways to use the File protocol.

以下示例演示了使用File协议的四种方法。

Copy

//Specifying a drive and a file name. 

file:///C|/My Documents/ALetter.html

//Specifying only a drive and a path to browse the directory. 

file:///C|/My Documents/

//Specifying a drive and a directory using the command line representation of the directory location. 

C:\My Documents\

//Specifying only the directory on the local primary drive. 

\My Documents\

http://msdn.microsoft.com/en-us/library/aa767731

#4


In case someone else finds this topic while using localhost in the file URIs - Internet Explorer acts completely different if the host name is localhost or 127.0.0.1 - if you use the actual hostname, it works fine (from trusted sites/intranet zone).

如果其他人在文件URI中使用localhost时发现此主题 - 如果主机名是localhost或127.0.0.1,则Internet Explorer的行为完全不同 - 如果使用实际主机名,则它可以正常工作(来自可信站点/内部网区域)。

Another big difference between IE and FF - IE is fine with uris like file://server/share/file.txt but FF requires additional slashes file:////server/share/file.txt.

IE和FF之间的另一个很大的区别 - IE对于像文件://server/share/file.txt这样的uris很好,但FF需要额外的斜杠文件:////server/share/file.txt。

#5


Paste following link to directly under link button click event, otherwise use javascript to call code behind function

将以下链接粘贴到链接按钮单击事件下,否则使用javascript调用函数后面的代码

Protected Sub lnkOpen_Click(ByVal sender As Object, ByVal e As EventArgs) 
    System.Diagnostics.Process.Start(FilePath)
End Sub

#6


At least with Chrome, (I don't know about Firefox) You can drag the icon to the left of the URL in the browser to a folder location on your desktop and it will create a file that behaves as an internet shortcut.

至少在Chrome上,(我不知道Firefox)您可以将浏览器中URL左侧的图标拖到桌面上的文件夹位置,它将创建一个充当互联网快捷方式的文件。

I don't know if the file format is universal yet, however Chrome seems to know what to do with it.

我不知道文件格式是否具有通用性,但Chrome似乎知道如何处理它。

The file produced is a .url file and contains the following:

生成的文件是.url文件,包含以下内容:

[InternetShortcut] URL=http://www.accordingtothescriptures.org/prophecy/353prophecies.html

You can replace the URL with anything you'd like.

您可以将URL替换为您想要的任何内容。