×

C#的WebBrowser操作frame

Kalet Kalet 发表于2009-03-20 12:00:14 浏览197 评论0

抢沙发发表评论

 


C#的WebBrowser操作frame



1.获取frame的源文件


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


2.获取frame的HTMLDocument接口


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


3.获取frame的IHTMLDocument2接口


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


4.取得frame中被点击的连接


private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{C#的WebBrowser操作frame
     string url = webBrowser1.Document.Window.Frames["main"].Document.ActiveElement.GetAttribute("src");
}


群贤毕至

访客