Select the product you need help with
- Internet Explorer
- Windows Phone
- More products
PRB: WebBrowser Control Disappears When Script Calls window.close()
Article ID: 253219 - View products that this article applies to.
This article was previously published under Q253219
When the script on a Web page calls the window.close property on itself, the WebBrowser control may disappear from the window. This article explains how to determine when this has occurred and how to take appropriate action.
In Internet Explorer 5.5, the WebBrowser control's default source interface, DWebBrowserEvents2, exposes a new event called WindowClosing. You can sink DWebBrowserEvents2 and set the Cancel parameter of the event to TRUE to prevent the close from occurring, or you can close the host windows.
In Internet Explorer 5.01 and earlier, the WM_PARENTNOTIFY message is sent to the parent of a child window when the child window is created or destroyed, or when the user clicks a mouse button while the cursor is over the child window. Thus, the hosting container of the WebBrowser control can watch for a WM_DESTROY notification message. If LOWORD of the wParam field of the WM_PARENTNOTIFY message is set to WM_DESTROY, the HIWORD of wParam contains the child window identifier, and the lParam field contains the hWnd of the child control. If the hWnd in lParam matches the hWnd of the WebBrowser control, you can determine that the WebBrowser control is being destroyed. You can then take the appropriate action, which typically means to close the child window for multiple-document interface (MDI) applications and quit the applications for single-document interface (SDI) applications.
When the script calls window.close, the WebBrowser control destroys its window, but the control is still in its "running" state (that is, the control is not completely destroyed). The WebBrowser control does not inform its container on deactivation through the IOleInPlaceSite::OnUIDeactivate method.
Handling the WM_PARENTNOTIFY message
Steps to Reproduce Behavior
For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:
http://msdn.microsoft.com/ie/(c) Microsoft Corporation 2000, All Rights Reserved. Contributions by %2, Microsoft Corporation.
Article ID: 253219 - Last Review: April 21, 2006 - Revision: 3.0