经过测试,终于找到了一种方法可以解决window.close的问题了 1 private void wb_Container_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
2 {
3 wb_Container.Document.Window.Unload += new HtmlElementEventHandler(Window_Unload);
4 }
5
6 void Window_Unload(object sender, HtmlElementEventArgs e)
7 {
8 if (this.wb_Container.Document == null)
9 this.Close();
10 } 原理:
1:代理window的unload事件。这个事件在页面卸载的时候触发。
2:在这个事件之后检查webbrowser的值。如果是window.close,那么属性为空。
可能这个方法还是不够好,但是现下可用了。