Accessing Framesets with Microsoft Visual Basic

See Also

Frames are an important part in the design of a web. FrontPage 2000 provides support for programming the content of frames. Click one of the following links for more information on a particular topic.

Exploring Frames

Role of a Frameset

Accessing HTML Tags

Dynamic Framesources

Iterating all Frames in a PageWindow

Changing Meta Tag Content to Another Character Set

Exploring Frames

Accessing frames within a frameset in FrontPage is relatively straightforward as long as you keep in mind that each frame accesses its own page and that you access the contents of each page through a Page object model object. The two windows involved with displaying frames area PageWindow object and an FPHTMLWindow2 object. The equivalent expression to access the contents in the window associated with the active frame is Set myActiveFrameInFrameset = ActivePageWindow.Document. The ActivePageWindow object accesses the page window for the frame, and the Document object accesses the FPHTMLWindow2 object.

Note   You may get permission denied errors if you try to access objects while in HTML view. When you want to add code or text to a document object, you must have the FpPageViewMode constant for the ViewMode property set to fpPageViewNormal. The value for view mode cannot be set to fpPageViewHtml or fpPageViewPreview. Alternatively, in the User Interface (UI), you cannot have the HTML tab or the Preview tab open in Page view in FrontPage.

Role of a Frameset

A framset is the container for all of the frames in a web window. Each frame is contained in an individual page window and has an individual page associated with it. By accessing the FrameWindow object from the Web object model, you access an FPHTMLWindow2 object that contains the frame page document. From these objects you can access the windows, documents, and frames of the frameset. In the following statement, myFrameset is an FPHTMLWindow2 object that returns the frames page document. From this object, you can access the <frame> and <frameset> tags, or the window or document objects.

Set myFrameset = ActivePageWindow.FrameWindow

This statement returns an FPHTMLWindow2 object through the Page object model. The Document property of myFrameset accesses the Page object model for the page that is equivalent to accessing the Frames Page HTML tab in Page view in FrontPage.

Note   The Frames Page HTML and No Frames tabs are only available when frames exist on the current page.

Accessing HTML Tags

You can access the same information that a frames tag accesses by declaring an object as a FPHTMLFrameElement. Some of the properties and methods available for this object include border, borderColor, click, frameBorder, frameSpacing, innerHTML, innerText, insertAdjecentHTML, and insertAdjacentText.

Dim myFramesElements() As FPHTMLFrameElement

You can access the information for a frameset tag by declaring an object a FPHTMLFramesetSite object.

Dim myFramesetSite As FPHTMLFramesetSite

Dynamic Framesources

You can dynamically change the framesource in the HTML code by using the following statements. This code sets the framesource to a new URL, Inventory_1stQuarter.htm.

Dim myDoc As Object

Set myDoc = ActivePageWindow.FrameWindow.Document

myDoc.all.tags("frame").Item(0).src = _
    "Inventory_1stQuarter.htm"

Iterating all Frames in a PageWindow

To access the properties of the frameset elements that reside in a particular frames page, you must access the FPHTMLDocument object through the Document property. The following example iterates through the frameset and frame elements for the active frameset in FrontPage. The frameset array (myFSElements) comprises each <FRAMESET> tag on the frames page. The frames array (myFramesElements) comprises each <FRAME> tag on the frames page. The frame windows array (myFramesWindows) comprises each FPHTMLWindow2 object that points to each frame. You populate each of the arrays by iterating through their respective tags or objects. Once the arrays are populated, you change the frameSpacing property in the frameset element to "10", the borderColor property to "red", and change various properties in the document.

Private Sub AccessFramesPage()
Dim myFPWindow As FPHTMLWindow2
Dim myFSElements() As IHTMLFrameSetElement
Dim myFramesWindows() As FPHTMLWindow2
Dim myFramesElements() As FPHTMLFrameElement
Dim myStyle As FPHTMLStyle
Dim i As Integer

Set myFPWindow = ActivePageWindow.FrameWindow
ReDim myFSElements(myFPWindow.Document.all.tags("FRAMESET").length)
ReDim myFramesElements(myFPWindow.Document.all.tags("FRAME").length)
ReDim myFramesWindows(myFPWindow.frames.length)

For i = 0 To UBound(myFSElements)
    Set myFSElements(i) = _
        myFPWindow.Document.all.tags("FRAMESET").Item(i)
Next i

i = 0
For i = 0 To UBound(myFramesWindows)
    Set myFramesWindows(i) = myFPWindow.frames(i)
Next i

i = 0
For i = 0 To UBound(myFramesElements)
    Set myFramesElements(i) = _
        myFPWindow.Document.all.tags("FRAME").Item(i)
Next i

myFSElements(0).frameSpacing = "10"
myFramesElements(0).borderColor = "red"

With myFramesWindows(2).Document
    .bgColor = "green"
    .body.innerHTML = "<p id=""cool""> Added by FP Programmability"
    Set myStyle = .all.cool.style
        myStyle.backgroundColor = "white"
        myStyle.display = False
        myStyle.textDecorationUnderline = True
        myStyle.Font = "Tahoma, 24"
        myStyle.fontStyle = "italic"
End With
End Sub

Changing Meta Tag Content to Another Character Set

You can change all of the content-type META Tags to a different character set (Central European) as shown in the following code sample. The current character set is shown in the Language Settings dialog box (available for Page Properties).

Note   The entire content-type META Tag contains a string similar to the following:

content = "text/html; charset = windows-1252

The character set is "windows-1252" and is the default character set for U.S. English.

Each time the program iterates through the loop, you access the next frame in the frameWindow object, which is the same as accessing each frames tag in HTML in succession. However, the frames collection does not support the For..each constuct. You cannot access HTTP-EQUIV type meta tags via their name, you must use an index instead as shown in the following example.The expression beginning with myContentType.Content sets the character set to Central European.

Note   FrontPage places the content type in META Tag zero.

Private Sub ChangeCharSet()
Dim myFrames As IHTMLFramesCollection2
Dim myFrame As FPHTMLWindow2
Dim myHTTPEquiv As String
Dim myContentType As Object
Dim myCount As Integer

Set myFrames = ActivePageWindow.FrameWindow.frames
Set myFrame = ActivePageWindow.FrameWindow.frames(0)
myHTTPEquiv = 0

For myCount = 0 To myFrames.Length - 1
    Set myFrame = myFrames(myCount)
    Set myContentType = _
        myFrame.Document.all.tags("meta").Item(myHTTPEquiv)
    myContentType.content = _
        "text/html; charset=iso-8859-2"
Next myCount
End Sub