Läs på engelska Redigera

Dela via


HtmlWindow.Document Property

Definition

Gets the HTML document contained within the window.

C#
public System.Windows.Forms.HtmlDocument Document { get; }
C#
public System.Windows.Forms.HtmlDocument? Document { get; }

Property Value

A valid instance of HtmlDocument, if a document is loaded. If this window contains a FRAMESET, or no document is currently loaded, it will return null.

Examples

The following code example inspects each document within a page containing frames and creates a table of all of the outgoing hyperlinks from each page for future inspection.

C#
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");
            }
        }
    }
}

Remarks

Typically, you will access the Document through the Document property of the WebBrowser control. Use this property when you need to access a document within a FRAME using the Frames collection.

Applies to

Produkt Versioner
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10