WebBrowser control: how to suppress a message: you want to close this window

I am new to managing WebBrowser. In the current project, we use the WebBrowser control to integrate with an existing project. All pop-ups are displayed in a new window form. When "javascript window: close" is called in a popup window, an IE prompt always appears: you want to close this window. We use WndProce to check WM_Destroy to notify the parent form, i.e. it is going to close, which works fine. The only thing we don’t like is that the message “you want to close this window”. Is there a way to suppress a message?

Any suggestion would be highly appreciated. Thanks.

+3
source share
2 answers

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

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

Or:

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

This is an IE security feature. The idea is to prevent potentially malicious scripts in order to close a window that the user does not want to close. The exception is that the window was opened by a script in the same domain, which indicates that the web application "owns" this window, so it can also close it. In this case, you will not receive a warning.

+2
source

Source: https://habr.com/ru/post/1718158/


All Articles