Registrations are now open. Join us today!
There is still a lot of work to do on the wiki yet! More information about editing can be found here.
Already have an account?

Microsoft KB Archive/251128

From BetaArchive Wiki

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.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Copy the following text into a new HTML file called NoNewWnd.htm:

    <HTML>
    <HEAD>
    <TITLE>NewWindow2 Test</TITLE>
    
    <SCRIPT LANGUAGE="JScript">
    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");
       }   
    }
    </SCRIPT>
    </HEAD>
    
    <BODY>
    <P><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>
                        
  2. Start a new Standard EXE project in Visual Basic. Form1 is created by default.
  3. 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.
  4. Create a new instance of the WebBrowser control on Form1.
  5. 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
                        
  6. 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.


REFERENCES

For additional information, please see the following MSDN Web Workshop Web sites:


Additional query words: IHTMLWindow2::showModalDialog, IHTMLWindow3::showModelessDialog

Keywords: kbnofix kbieobj kbprb kbdhtml KB251128