views:

566

answers:

2

Hi, 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.

+2  A: 

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();
}
Druid
The 2nd option worked for me in IE. Exactly what are you instructing the browser to do?
deostroll
It opens a new window with no specific url with target '_self' which means that the target window is the window where this is run. The effect is that the document windows makes it's own window the opener window, and thus takes ownership of it. Then it will have access to close itself, since it has opened it...
awe
+1  A: 

This is a security feature of IE. The idea is to prevent potentially malicious scripts to close a window that the user did not want to be closed. The exception is if the window was opened by a script on the same domain, which indicates that it is the web application that "owns" the window, so it can also close it. In this case you don't get the warning.

awe