Modifying Pages Programmatically

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

This topic illustrates how to work with the Document object elements within the Web object model environment, either to change the contents of a page or simply to access the contents of a page for verification.

Microsoft Visual Basic is a powerful tool that you can use to modify content in your web pages. As you browse through the Object Browser, you'll see many of the same types of components that you're familiar with in Microsoft Internet Explorer.

Tip   To only view the programming elements that are compatible with the Page object model of FrontPage, select "FrontPageEditor" as the object library in the Object Browser.

You can access the HTML elements of a page using the ActiveDocument or Document properties that return the document object via the PageWindow object. For example, the following statement changes the color of the background for the page in the active page window.

ActivePageWindow.Document.bgColor = "DarkBlue"

The following example checks for a specific hyperlink (index.htm) within the active document. If the hyperlink is found, the procedure exits, if the hyperlink isn't found, the procedure first checks if the active document is index.htm and, if not, the hyperlink is added at the end of the document.

Private Sub VerifyIndexLink()
Dim myDoc As FPHTMLDocument
Dim myLinks As Variant
Dim myLink As Variant
Dim myNumberOfLinks As Integer
Dim myAddLink As Boolean
Dim myLinkName As String
Dim myLinkName2 As String

Set myDoc = ActivePageWindow.Document
Set myLinks = myDoc.Links
myNumberOfLinks = myLinks.length
myLinkName = "index.htm"
myLinkName2 = """" & myLinkName & """"

For Each myLink In myLinks
    If myLink = myLinkName Then
        myAddLink = True
        Exit For
    End If
Next

If myAddLink = False And myDoc.nameProp <> "index" Then
    Call myDoc.body.insertAdjacentHTML("BeforeEnd", "<a href=" _
        & myLinkName2 & ">" & myLinkName & "</a>")
    ActivePageWindow.Save
End If
End Sub

Tip   Notice that in the last If statement the active page window is saved before exiting the procedure. This would be a good statement to add to the OnPageClose event.