简体   繁体   English

C#WebBrowser-作用于javascript window.close(); (act =覆盖关闭WinForm窗口)

[英]C# WebBrowser - act on javascript window.close(); (act= override close WinForm window)

I have an web application containing a javascript block which wants to close the opened window. 我有一个包含javascript块的Web应用程序,它想关闭打开的窗口。 This is done by window.close(); 这是通过window.close();完成的window.close();

I'm hosting this application in a C# WebBrowser WinForm project. 我将这个应用程序托管在C# WebBrowser WinForm项目中。 When the javascript code window.close(); 当javascript代码window.close(); gets called, I'm getting a MessageBox question from the WebBrowser. 被调用,我从WebBrowser收到一个MessageBox问题。 This says 'The Webpage is trying to close the window...'. 这表示“网页正在尝试关闭窗口...”。 If clicked yes, the WinForm window will close. 如果单击是,WinForm窗口将关闭。

My issue is that I would like to allow javascript to close this window, I don't want this warning message to appear. 我的问题是我想允许javascript关闭此窗口,我不希望出现此警告消息。

Any ideas? 有任何想法吗? I've tried overriding WinForm FormClosing event , but this message happens directly in the WebBrowser. 我尝试覆盖WinForm FormClosing event ,但是此消息直接在WebBrowser中发生。 I have also overrided WndProc in WM_PARENTNOTIFY (0x210), on WM_DESTROY . 我还在WM_PARENTNOTIFY (0x210), on WM_DESTROY覆盖了WndProc However this is called after the question is answered in the WebBrowser warning. 但是,在WebBrowser警告中回答问题后调用此方法。

Adding these for window closing in javascript works great: 添加这些以在javascript中关闭窗口效果很好:

window.open('', '_self');
window.close();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM