This article was previously published under Q251128
This article has been archived. It is offered "as is" and will no longer be updated.
Calling showModalDialog or showModelessDialog does not fire the NewWindow2 event. This applies to DWebBrowserEvents2::NewWindow2 as well as its Microsoft Visual Basic equivalent, the NewWindow2 event for the WebBrowser and InternetExplorer objects.
The NewWindow2 event is only fired when a new instance of Internet Explorer is about to be created. The modal/modeless dialogs are not new instances of Internet Explorer. They are implemented as MSHTML host windows, allowing them to render and display HTML content (but not hyperlinks between documents). Furthermore, they do not appear in the taskbar and are closed whenever the window that created them is closed.
This behavior is by design.
Steps to Reproduce Behavior
Copy the following text into a new HTML file called NoNewWnd.htm:
Start a new Standard EXE project in Visual Basic. Form1 is created by default.
Add a reference to the WebBrowser control by selecting Components on the Project menu and selecting Microsoft Internet Controls (Shdocvw.dll).
The WebBrowser control will appear in the Toolbox.
Create a new instance of the WebBrowser control on Form1.
Copy the following code into the code window of Form1.
Private Sub Form_Load() ' Replace "C:\noNewWnd.htm" with the absolute path ' to the HTML file you created in Step 1. strFileName = "C:\noNewWnd.htm" WebBrowser1.Navigate2 strFileNameEnd SubPrivate Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean) MsgBox "I just caught NewWindow2!"End Sub
From the Run menu, click Start or press the F5 key to start the program. Click on each of the three buttons and observe the behavior.
NOTE: The showModalDialog method was not available prior to Internet Explorer 5 and will cause a run-time error on those versions.
For additional information, please see the following MSDN Web Workshop Web sites: