[英]How to handle “window.Close” JS in a WebBrowser in c#
I have to code a program for a library, I have to embed a Web Browser for a website but the Web Browser can't be close. 我必须为图书馆编写程序,必须为网站嵌入Web浏览器,但不能关闭Web浏览器。 So I have cancel closing but when a user clicks on a button in JS for closing window (window.Close) the program crash.
因此,我取消了关闭,但是当用户单击JS中的按钮以关闭窗口(window.Close)时,程序崩溃。 I add :
我加 :
HtmlDocument htmlDocument = this.webBibliotheque.Document;
htmlDocument.Window.Unload += new HtmlElementEventHandler(Window_Unload);
when the Document is charged. 收取文件费用时。 This code works and gets to catch the evenment but I don't know what I have to do in my function :
这段代码可以正常工作,但是我不知道我必须在函数中做什么:
void Window_Unload(object sender, HtmlElementEventArgs e)
{
}
Can anyone help me please? 谁能帮我吗?
You should handle the WindowClosing
event on the underlying WebBrowser
ActiveX Control ( WebBrowser.ActiveXInstance
). 您应该在基础
WebBrowser
ActiveX控件( WebBrowser.ActiveXInstance
)上处理WindowClosing
事件。 There is an option to cancel it (disclaimer: untested). 有一个选项可以取消它(免责声明:未经测试)。 Check this answer for more details on how to handle the "raw" WebBrowser events like this.
检查此答案以获取有关如何处理此类“原始” WebBrowser事件的更多详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.