How do I make a file:// hyperlink that works in both IE and Firefox?

前端 未结 5 714
太阳男子
太阳男子 2020-12-30 08:50

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

In IE, this works fine with URLs f

相关标签:
5条回答
  • 2020-12-30 09:23

    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).

    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.

    0 讨论(0)
  • 2020-12-30 09:24

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

    Syntax

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

    sDrives
    Specifies the local or network drive.

    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.

    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:.

    Available as of Microsoft Internet Explorer 3.0 or later.

    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.

    Example

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

    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

    0 讨论(0)
  • 2020-12-30 09:29

    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.

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

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

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

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

    0 讨论(0)
  • 2020-12-30 09:33

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

    Protected Sub lnkOpen_Click(ByVal sender As Object, ByVal e As EventArgs) 
        System.Diagnostics.Process.Start(FilePath)
    End Sub
    
    0 讨论(0)
  • 2020-12-30 09:39

    just use

    file:///
    

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

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

    0 讨论(0)
提交回复
热议问题