Share via


HtmlWindow.Document Propiedad

Definición

Obtiene el documento HTML incluido en la ventana.

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

Valor de propiedad

HtmlDocument

Instancia válida de HtmlDocument, si se carga un documento. Si esta ventana contiene un FRAMESET o no se carga ningún documento actualmente, devolverá null.

Ejemplos

En el ejemplo de código siguiente se inspecciona cada documento dentro de una página que contiene marcos y se crea una tabla de todos los hipervínculos salientes de cada página para una inspección futura.

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

Comentarios

Normalmente, tendrá acceso a Document a través de la Document propiedad del WebBrowser control . Utilice esta propiedad cuando necesite tener acceso a un documento dentro de un FRAME mediante la Frames colección .

Se aplica a