为什么 WebBrowser 控件有这种奇怪的行为?
我有一个带有 webbrowser
的表单。事件:Navigating
、Naviged
和 DocumentCompleted
已附加。
这就是我告诉它后得到的结果 .Navigate(new Url("http://google.com"));
20:42:42:036: 1. Navigating to: http://google.com/
20:42:42:545: 2. Navigated: http://www.google.com/
20:42:42:854: 3. Navigating to: about:blank
20:42:43:002: 4. Navigated: about:blank
20:42:43:004: 5. Loaded: about:blank
20:42:43:158: 6. Loaded: http://www.google.com/
有人能解释一下为什么我得到这个 about:blank东西?
该代码仅显示每个事件处理程序的 e.Url
参数。
I have a form with a webbrowser
. Events: Navigating
, Navigated
and DocumentCompleted
are attached.
This is what I am getting after telling it .Navigate(new Url("http://google.com"));
20:42:42:036: 1. Navigating to: http://google.com/
20:42:42:545: 2. Navigated: http://www.google.com/
20:42:42:854: 3. Navigating to: about:blank
20:42:43:002: 4. Navigated: about:blank
20:42:43:004: 5. Loaded: about:blank
20:42:43:158: 6. Loaded: http://www.google.com/
Can somebody explain why I am getting this about:blank
stuff?
The code is just displaying the e.Url
parameter of each event handler.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎自动导航到 about:blank 是一种已知的“安全毯”,由
WebBrowser
对象使用,以确保 HTML 对象在尝试加载您请求的页面之前有效,如中所述这篇 MSDN 文章:此外,
DocumentCompleted
事件应该可以工作。您确定您的活动没有做任何其他事情吗?我已经尝试过这个简单的代码,它按预期工作:
按下按钮后,您会得到以下内容:
It appears that the automatic navigation to about:blank is a known "security blanket" of sorts used by the
WebBrowser
object to ensure the HTML object is valid before trying to load the page you request, as explained in this MSDN article:Also, the
DocumentCompleted
event should work. Are you sure your events aren't doing anything else?I've tried this simple code, and it works as expected:
After pushing the button, you get the following: