C#的WebBrowser操作frame实例解析
作者:shichen2014 时间:2022-03-02 03:46:43
本文实例讲述了用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#学习能起到一定的帮助作用。
标签:C#,WebBrowser,frame
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java 反射调用静态方法的简单实例
2021-10-09 06:47:58
Java HtmlEmail 邮件发送的简单实现代码
2023-04-14 21:29:25
![](https://img.aspxhome.com/file/2023/8/111448_0s.png)
java实现KFC点餐系统
2021-09-06 11:36:34
![](https://img.aspxhome.com/file/2023/4/110634_0s.png)
ActiveMQ安装及部署教程图解
2023-11-17 18:01:46
![](https://img.aspxhome.com/file/2023/3/59483_0s.png)
java实现构造无限层级树形菜单
2021-11-11 05:46:22
Android仿微信联系人字母排序效果
2021-10-01 16:06:25
![](https://img.aspxhome.com/file/2023/1/90121_0s.gif)
Java ArrayList实现删除指定位置的元素
2023-11-25 05:34:13
![](https://img.aspxhome.com/file/2023/0/60160_0s.png)
spring多数据源配置实现方法实例分析
2023-06-06 22:15:56
详解SpringBoot迭代发布JAR瘦身配置
2021-11-14 19:10:48
![](https://img.aspxhome.com/file/2023/0/86850_0s.png)
SpringBoot集成vue的开发解决方案
2023-11-24 20:58:10
![](https://img.aspxhome.com/file/2023/8/59028_0s.png)
详解Android通知栏沉浸式/透明化完整解决方案
2023-09-06 03:59:11
![](https://img.aspxhome.com/file/2023/2/100642_0s.gif)
MyBatis源码浅析(一)开篇
2022-09-28 03:28:24
Android使用onCreateOptionsMenu()创建菜单Menu的方法详解
2023-05-13 06:21:01
winform 实现控制输入法
2022-05-01 11:35:38
Java中文件操作功能小结
2023-06-20 03:32:28
![](https://img.aspxhome.com/file/2023/8/87348_0s.webp)
C#实现HSL颜色值转换为RGB的方法
2022-02-21 09:56:11
Java之JFrame输出Helloworld实例
2022-01-19 16:40:52
![](https://img.aspxhome.com/file/2023/5/71185_0s.png)
SpringBoot从yml配置文件中读常用参数值实例方法
2021-07-01 11:12:04
Java字节码中jvm实例用法
2023-08-08 05:25:09
Spring容器初始化及问题解决方案
2023-09-14 08:19:32