WebBrowser控件:检测导航失败 [英] WebBrowser control: Detect navigation failure

查看:431
本文介绍了WebBrowser控件:检测导航失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我托管一个webbrowser控件,通常加载外部文档,然后使用HTML DOM进行一些修改。



我们还使用假协议嵌入自定义应用程序链接,例如在 BeforeNavigate2 中捕获并处理的关闭此。

当链接tarket拼写错误说,spp:CloseWindow),BeforeNavigate将不会触发自定义处理。浏览器控件不显示导航错误,但保持在READYSTATE_INTERACTIVE,并且不触发 NavigateComplete DocumentComplete






我的问题:
大多数操作(例如检索或更新内容)被延迟,并等待readystate达到 READYSTATE_COMPLETE 。在点击这样的无效链接后,浏览器不再更新了 - 我想避免的状态。




  • 我可以在DownloadComplete中检测到导航失败吗?
    (所以我可以放松测试READYSTATE_COMPLETE READYSTATE_INTERACTIVE和上次下载完成

  • 我可以将浏览器控制重置为READYSTATE_COMPLETE(可能不是)

  • 我可以检测浏览器实际支持的伪协议吗?



(事后来看,使用 xxxx:前缀不是这样的好的主意,但改变现在有点问题。)

解决方案

Internet Explorer和Windows有可扩展的可用列表协议在UrlMon.dll中实现,我相信。请参阅这里有关 IE架构的资讯。



在BeforeNavigate中无法检测到坏协议的原因是协议未知,因此没有实际的导航发生。浏览器决定显示错误页面。错误页面导航不会明显提高所有正常事件。



但是,有一种方法来检测导航已经进入杂草。如果您连接到Web浏览器的DocumentCompleted事件,您可以扫描与错误相关联的特定URL,或者更一般地,任何具有以res://ieframe.dll开头的URL。



示例:




  • res://ieframe.dll/unknownprotocol.htm#spp:CloseWindow

  • res://ieframe.dll/dnserrordiagoff_webOC.htm# http:// 192 ...



一个更简单的方法是挂钩到 DWebBrowserEvents2接口


I am hosting a webbrowser control, that usually loads an external documents, then makes some modifications using HTML DOM.

We also embed custom application links using a fake protocol, such as "Close This" that are caught and handled in BeforeNavigate2.

When the link tarket is misspelled (say, "spp:CloseWindow"), BeforeNavigate will not trigger custom handling. The Browser control does not show an navigaiton error, but remains in READYSTATE_INTERACTIVE and doesn't fire a NavigateComplete or DocumentComplete.


My Problem: Most operations (e.g. retrieving or updating the contents) are delayed and wait for the readystate reaching READYSTATE_COMPLETE. After such an invalid link is clicked, the browser doesn't get updated anymore - a state I'd like to avoid. How can I do that?

  • Can I detect in "DownloadComplete" that navigation failed? (So I could relax the test to "READYSTATE_COMPLETE or READYSTATE_INTERACTIVE and last downloadComplete was broken")
  • Can I "reset" the browser control to READYSTATE_COMPLETE (probably not)
  • Could I detect the pseudoprotocols actually supported by the browser?

(In hindsight, using an xxxx: prefix wasn't such a good idea, but changing that now is a bit of a problem.)

解决方案

Internet Explorer and Windows have an extensible list of available protocols implemented in UrlMon.dll, I believe. See here for a bit about IE architecture.

The reason you cannot detect the bad protocol in BeforeNavigate is that the protocol is unknown, so no real navigation is happening. The browser decides to show an error page instead. Error page navigation does not evidently raise all the normal events.

However, there is a way to detect when navigation has gone in the weeds. If you hook up to the web browser's DocumentCompleted event, you can scan for particular URLs associated with errors, or more generally, anything with a URL that starts with res://ieframe.dll.

Examples:

  • res://ieframe.dll/unknownprotocol.htm#spp:CloseWindow
  • res://ieframe.dll/dnserrordiagoff_webOC.htm#http://192...

A cleaner way is to hook into the NavigateError of the DWebBrowserEvents2 interface.

这篇关于WebBrowser控件:检测导航失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆