Microsoft KB Archive/251128

= PRB: showModalDialog and showModelessDialog Do Not Fire NewWindow2 =

Article ID: 251128

Article Last Modified on 5/12/2007

-

APPLIES TO


 * Microsoft Internet Explorer 4.0 128-Bit Edition
 * Microsoft Internet Explorer 4.01 Service Pack 2
 * Microsoft Internet Explorer 4.01 Service Pack 1
 * Microsoft Internet Explorer 4.01 Service Pack 2
 * Microsoft Internet Explorer 5.0
 * Microsoft Internet Explorer 5.01

-



This article was previously published under Q251128



SYMPTOMS
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.



CAUSE
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.



STATUS
This behavior is by design.



Steps to Reproduce Behavior
  Copy the following text into a new HTML file called NoNewWnd.htm:   NewWindow2 Test

 function openNewWindow(szMethod) { if (szMethod == "modal") { window.showModalDialog("http://msdn.microsoft.com/workshop"); }  else if (szMethod == "modeless") { window.showModelessDialog("http://msdn.microsoft.com/workshop"); }  else { window.open("http://msdn.microsoft.com/workshop"); }  }  

 <INPUT type="button" value="window.open" id=button1 name=button1 onclick="openNewWindow('normal');"><BR> <INPUT type="button" value="showModalDialog" id=button2 name=button2 onclick="openNewWindow('modal');"><BR> <INPUT type="button" value="showModelessDialog" id=button3 name=button3 onclick="openNewWindow('modeless');"></P> </BODY> </HTML> </li> <li>Start a new Standard EXE project in Visual Basic. Form1 is created by default.</li> <li>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.</li> <li>Create a new instance of the WebBrowser control on Form1.</li> <li> 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 strFileName End Sub

Private Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean) MsgBox "I just caught NewWindow2!" End Sub </li> <li>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.</li></ol>

<div class="references_section">