C# – WebBrowser control: how to suppress message: do you want to close this window

cinternet explorerwebbrowser-controlwndproc

I'm new to WebBrowser control. In the current project, we use WebBrowser control to integrate with existing project. All popup windows are displayed in a new windows form. When "javascript window:close" is called on the popup window, the IE instance always prompt: do you want to close this window. We're using WndProce to check WM_Destroy to notify the parent form the ie is about to close which works fine. The only thing we don't like the control is that the message "do you want to close this window". Is there any way to suppress the message?

Any suggestion will be highly appreciated. Thanks.

Best Answer

Try using either of the following two functions to close the popup:

function closeWindow()
{
    window.opener = self;
    window.close();
}

Or:

function closeWindow()
{
    window.open('', '_self');
    window.close();
}