C# 中控件 WebBrowser 對 frameset/ iframe 操做和內容獲取

1.獲取frame的document

  HtmlDocument htmlDoc = webBrowser1.Document;
  htmlDoc = webBrowser1.Document.Window.Frames["frmRpt"].Document;  //  "frmRpt"爲iframe的name;html

 

2.獲取frame的源文件web

   MessageBox.Show(webBrowser1.Document.Window.Frames["main"].Document.Body.InnerHtml);post

 

3.獲取frame的HTMLDocument接口url

  HTMLDocument doc = (HTMLDocument)webBrowser1.Document.DomDocument;
  object j;
     for (int i = 0; i < doc.parentWindow.frames.length; i++)
    {
       j = i;
       HTMLWindow2Class frame = doc.parentWindow.frames.item(ref j) as HTMLWindow2Class;
       if (frame.name == "main")
        {                  
              MessageBox.Show(frame.document.title);                   
        }
    }     spa

 

 

4.獲取frame的IHTMLDocument2接口htm

IHTMLDocument2 doc = (IHTMLDocument2)webBrowser1.Document.Window.Frames["main"].Document.DomDocument;blog

 

5.取得frame中被點擊的鏈接接口

private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
      string url = webBrowser1.Document.Window.Frames["main"].Document.ActiveElement.GetAttribute("src");
}iframe

相關文章
相關標籤/搜索