积极答复者
WebBrowser中关于Document事件注册失效

问题
-
问题描述:
给WebBrowser的DocumentCompleted事件添加方法,如下:
internal void handleDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) {
Log.println(" ******* document = "+this.webBrowserEx1.Document.GetHashCode());
if(listenedDocument == null || !listenedDocument.Equals(this.webBrowserEx1.Document)){
addRecordListeners();
listenedDocument = this.webBrowserEx1.Document ;
Console.WriteLine(" ++++++++++++++++++++++++++++++++++++ Download completed, add document listener . url = " + this.webBrowserEx1.Url);
}
}
private void addRecordListeners() {
this.webBrowserEx1.Document.MouseMove += new HtmlElementEventHandler(Document_MouseMove);
}
操作对象为126邮箱,当在第一页的时候,自动天剑Document_MouseMove方法成功,登陆邮箱,跳转到邮箱登陆后的页面,从日志看,browser的Document对象没有变化(哈希值一样),但是,Document_MouseMove方法就不起作用了,既然Document对象没有变化,有没有地方移除注册的Document_MouseMove方法,为什么就不起作用了呢?
原始的初衷:只想只在Documen对象发生变化的时候注册一次Document_MouseMove方法,减少注册的次数,后改成这样,只要有DocumentComplete事件就触发下面的代码,但是问题依旧,在登入到126的邮箱成功后,Document_MouseMove方法就不起作用了。
internal void handleDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) {
Log.println(" ******* document = "+this.webBrowserEx1.Document.GetHashCode());
addRecordListeners();
}
求高手明示,谢谢
- 已编辑 cylixhui 2011年8月22日 6:50
答案
-
IE开发人员工具的哪个功能让你感觉它可以捕捉到HtmlDocument.MouseMove事件的,可以帮助我指出来吗?
就我所知会让人感觉到它在捕捉鼠标移动事件的是(Ctrl+B)选择html元素的那个功能,但我认为这有可能不是在捕捉HtmlDocument.MouseMove事件,而是使用Microsoft Active Accessibility Architecture
这里有一篇中文的介绍: http://www.vckbase.com/document/viewdoc/?id=883
这里还有一篇关于怎么使用.net调用此API的: http://www.codeproject.com/KB/winsdk/MSAA_UI_Automation.aspx
Mike [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Mike Dos ZhangModerator 2011年9月8日 3:53
- 取消答案标记 Mike Dos ZhangModerator 2011年9月8日 3:54
- 已标记为答案 cylixhui 2011年10月18日 0:59
全部回复
-
这有可能是126页面的设计,阻止了用户去监听文档的一些事件。
你的方法的使用没有问题。
你可以到126的服务网站寻求该页面官方的解释和帮助:http://help.163.com/
Mike [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Mike Dos ZhangModerator 2011年9月8日 3:53
- 取消答案标记 Mike Dos ZhangModerator 2011年9月8日 3:54
-
我没怎么用过firefox产品,更别说firedebug插件了,你可以解释一下你是怎么用firedebug来监听你的鼠标移动的事件的吗?
谢谢!
Mike [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
-
本人做法是在文档加载完毕后,遍历iframe,并给其添加事件。
在WebBrowser.DocumentComplete事件中添加下面的语句处理iframe
foreach (HtmlWindow fw in this.webBrowserEx1.Document.Window.Frames) {
}
执行过程终会抛出 threw an exception of type 'System.UnauthorizedAccessException', 坐等高手飘过,如何给文档中的iframe添加mouseMove事件???例如IE的开发工具就可以捕获iframe里面的元素并高亮。
-
IE开发人员工具的哪个功能让你感觉它可以捕捉到HtmlDocument.MouseMove事件的,可以帮助我指出来吗?
就我所知会让人感觉到它在捕捉鼠标移动事件的是(Ctrl+B)选择html元素的那个功能,但我认为这有可能不是在捕捉HtmlDocument.MouseMove事件,而是使用Microsoft Active Accessibility Architecture
这里有一篇中文的介绍: http://www.vckbase.com/document/viewdoc/?id=883
这里还有一篇关于怎么使用.net调用此API的: http://www.codeproject.com/KB/winsdk/MSAA_UI_Automation.aspx
Mike [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Mike Dos ZhangModerator 2011年9月8日 3:53
- 取消答案标记 Mike Dos ZhangModerator 2011年9月8日 3:54
- 已标记为答案 cylixhui 2011年10月18日 0:59