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.
You can access the HTML elements of a page using the ActiveDocument or Document properties that return the document object via the PageWindowEx object. For example, the following statement changes the background color 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, but 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
Note 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.