MakeRel 方法

       

Application 对象更改为相对对象而不是绝对对象。有关绝对和相对 URL 的详细信息,请参阅了解绝对和相对 URL 地址

expression.MakeRel(URLBaseURL)

expression  该表达式返回 Application 对象。

URLBase  必选,Variant 类型。基本 URL。可以是下列类型之一:字符串或者 WebEx、WebFolder、WebFile、NavigationNode 或 IHTMLDocuemnt2 类型的对象。

URL  必选,String 类型。该字符串包含整个 URL。这可以是站点的任何 URL,如 http://Web 服务器/文件夹或file://文件系统/文件夹(对于基于磁盘的站点)。

示例

本示例将绝对 URL 更改为相对 URL,并且使用相对 URL 将超链接添加到当前文档中,然后将所做更改保存到当前网页窗口。

注意  要运行本示例,必须有一个称为“C:\My Documents\My Webs\Rogue Cellars”(对于在 Microsoft Windows 上运行的服务器)或“C:\WINNT\Profiles\logon alias\Personal\My Webs\Rogue Cellars”(对于在 Windows NT 上运行的服务器)的站点。还必须有两个文件,一个称为“Zinfandel.htm”,另一个称为“index.htm”,它们拥有绝对 URL(默认状态)。或者,您可以用其他站点 URL 和其他文件名来代替。

Private Sub MakeURLRelative()
    Dim myFile As WebFile
    Dim myFile2 As WebFile
    Dim myBaseURL As WebEx
    Dim myDoc As FPHTMLDocument
    Dim myRelAddress As String
    Dim myRelAddress2 As String

    Set myBaseURL = Webs.Open("C:\My Documents\My Webs\Rogue Cellars")
    Set myFile = myBaseURL.RootFolder.Files("Zinfandel.htm")
    Set myFile2 = myBaseURL.RootFolder.Files("index.htm")
    Set myDoc = myFile.Edit(fpPageViewNormal).Document

    myRelAddress = MakeRel(myBaseURL, myFile2.Url)
    myRelAddress2 = """" & myRelAddress & """"
    Call myDoc.body.insertAdjacentHTML("BeforeEnd", "<a href=" _
            & myRelAddress2 & ">" & myRelAddress & "</a>")
    ActivePageWindow.Save
End Sub