软件编程
位置:首页>> 软件编程>> C#编程>> C#的WebBrowser操作frame实例解析

C#的WebBrowser操作frame实例解析

作者:shichen2014  发布时间:2022-03-02 03:46:43 

标签:C#,WebBrowser,frame

本文实例讲述了用WebBrowser操作frame和iframe的方法,比较适合C#初学者参考学习。示例浅显易懂,具体方法如下:
 
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;
  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)
{
  string url = webBrowser1.Document.Window.Frames["main"].Document.ActiveElement.GetAttribute("src");
}

希望本文所述实例对大家的C#学习能起到一定的帮助作用。

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com