HtmlWindow.Frames 屬性

定義

會取得網頁中定義的每個 FRAME 元素的參考。

public:
 property System::Windows::Forms::HtmlWindowCollection ^ Frames { System::Windows::Forms::HtmlWindowCollection ^ get(); };
public System.Windows.Forms.HtmlWindowCollection Frames { get; }
public System.Windows.Forms.HtmlWindowCollection? Frames { get; }
member this.Frames : System.Windows.Forms.HtmlWindowCollection
Public ReadOnly Property Frames As HtmlWindowCollection

屬性值

HtmlWindowCollection FRAME文件和IFRAME物件的一部分。

範例

以下程式碼範例檢查包含框架的頁面內的每份文件,並建立每頁所有外出超連結的表格,供未來檢查。

private void GetLinksFromFrames()
{
    Hashtable linksTable = new Hashtable();
    string frameUrl;

    if (!(webBrowser1.Document == null))
    {
        HtmlWindow currentWindow = webBrowser1.Document.Window;
        if (currentWindow.Frames.Count > 0)
        {
            foreach (HtmlWindow frame in currentWindow.Frames)
            {
                frameUrl = frame.Url.ToString();
                Hashtable frameLinksHash = new Hashtable();

                linksTable.Add(frameUrl, frameLinksHash);
                foreach (HtmlElement hrefElement in frame.Document.Links)
                {
                    frameLinksHash.Add(hrefElement.GetAttribute("HREF"), "Url");
                }
            }
        }
        else
        {
            Hashtable docLinksHash = new Hashtable();
            linksTable.Add(webBrowser1.Document.Url.ToString(), docLinksHash);

            foreach (HtmlElement hrefElement in webBrowser1.Document.Links)
            {
                docLinksHash.Add(hrefElement.GetAttribute("HREF"), "Url");
            }
        }
    }
}
Dim LinksTable As Hashtable

Private Sub GetLinksFromFrames()
    LinksTable = New Hashtable()
    Dim FrameUrl As String

    If (WebBrowser1.Document IsNot Nothing) Then
        With WebBrowser1.Document
            Dim CurrentWindow As HtmlWindow = .Window
            If (CurrentWindow.Frames.Count > 0) Then
                For Each Frame As HtmlWindow In CurrentWindow.Frames
                    FrameUrl = Frame.Url.ToString()
                    Dim FrameLinksHash As New Hashtable()
                    LinksTable.Add(FrameUrl, FrameLinksHash)

                    For Each HrefElement As HtmlElement In Frame.Document.Links
                        FrameLinksHash.Add(HrefElement.GetAttribute("HREF"), "Url")
                    Next
                Next
            Else
                Dim DocLinksHash As New Hashtable()
                LinksTable.Add(.Url.ToString(), DocLinksHash)

                For Each HrefElement As HtmlElement In .Links
                    DocLinksHash.Add(HrefElement.GetAttribute("HREF"), "Url")
                Next
            End If
        End With
    End If
End Sub

備註

A FRAME 是定義在 FRAMESET內的一組視窗。 FRAMES允許在單一文件中托管多個文件。 每個 FRAME s 定義為具有特定的列與欄寬,且在頁面上相對於其他 FRAME定義的 FRAMESETs 位置;a FRAME 的位置是固定的,儘管使用者有時會使用滑鼠游標來放大或縮小 FRAME。 an IFRAME 類似於框架,但不必固定固定位置。

框架會包含一個實例HtmlWindow,對應FRAMEIFRAME每個或定義於網頁內。

適用於

另請參閱