Microsoft KB Archive/251128: Difference between revisions
m (Text replacement - ">" to ">") |
m (Text replacement - """ to """) |
||
Line 78: | Line 78: | ||
<TITLE>NewWindow2 Test</TITLE> | <TITLE>NewWindow2 Test</TITLE> | ||
<SCRIPT LANGUAGE= | <SCRIPT LANGUAGE="JScript"> | ||
function openNewWindow(szMethod) { | function openNewWindow(szMethod) { | ||
if (szMethod == | if (szMethod == "modal") { | ||
window.showModalDialog( | window.showModalDialog("http://msdn.microsoft.com/workshop"); | ||
} | } | ||
else if (szMethod == | else if (szMethod == "modeless") { | ||
window.showModelessDialog( | window.showModelessDialog("http://msdn.microsoft.com/workshop"); | ||
} | } | ||
else { | else { | ||
window.open( | window.open("http://msdn.microsoft.com/workshop"); | ||
} | } | ||
} | } | ||
Line 94: | Line 94: | ||
<BODY> | <BODY> | ||
<P><INPUT type= | <P><INPUT type="button" value="window.open" id=button1 name=button1 onclick="openNewWindow('normal');"><BR> | ||
<INPUT type= | <INPUT type="button" value="showModalDialog" id=button2 name=button2 onclick="openNewWindow('modal');"><BR> | ||
<INPUT type= | <INPUT type="button" value="showModelessDialog" id=button3 name=button3 onclick="openNewWindow('modeless');"></P> | ||
</BODY> | </BODY> | ||
</HTML> | </HTML> | ||
Line 107: | Line 107: | ||
<li><p>Copy the following code into the code window of Form1.</p> | <li><p>Copy the following code into the code window of Form1.</p> | ||
<pre class="codesample">Private Sub Form_Load() | <pre class="codesample">Private Sub Form_Load() | ||
' Replace | ' Replace "C:\noNewWnd.htm" with the absolute path | ||
' to the HTML file you created in Step 1. | ' to the HTML file you created in Step 1. | ||
strFileName = | strFileName = "C:\noNewWnd.htm" | ||
WebBrowser1.Navigate2 strFileName | WebBrowser1.Navigate2 strFileName | ||
End Sub | End Sub | ||
Private Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean) | Private Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean) | ||
MsgBox | MsgBox "I just caught NewWindow2!" | ||
End Sub | End Sub | ||
</pre></li> | </pre></li> |
Latest revision as of 13:52, 21 July 2020
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
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>
- 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 strFileName End Sub Private 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.
REFERENCES
For additional information, please see the following MSDN Web Workshop Web sites:
showModalDialog Method
http://msdn2.microsoft.com/en-us/library/ms536759.aspx
showModelessDialog Method
http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/showmodelessdialog.asp
NewWindow2 Event
http://msdn.microsoft.com/workshop/browser/webbrowser/reference/events/NewWindow2.asp
Additional query words: IHTMLWindow2::showModalDialog, IHTMLWindow3::showModelessDialog
Keywords: kbnofix kbieobj kbprb kbdhtml KB251128