Microsoft KB Archive/294870

= BUG: Using NewWindow or NewWindow2 to Always Navigate in the Same Window Fails in Some Instances =

Article ID: 294870

Article Last Modified on 5/11/2006

-

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
 * Microsoft Internet Explorer (Programming) 5.01 SP1
 * Microsoft Internet Explorer 5.5

-



This article was previously published under Q294870



SYMPTOMS
When you host the WebBrowser control, you may want navigation to always occur in the same window. In this case, you can process the NewWindow or NewWindow2 notification to cancel the navigation. However, the NewWindow and NewWindow2 events do not always work as expected.

Symptoms in Internet Explorer 5.5
When you use the NewWindow event in Internet Explorer 5.5, you may encounter the following problems:
 * If you click a link that performs a window.open method to browse to a new site, you can successfully browse to the site the first time; however, it fails the second time.
 * If you right-click a link and then click Open in New Window, it works the first time but does not work on subsequent attempts.

When you use the NewWindow2 event in Internet Explorer 5.5, you may encounter the following problems:
 * If you click a link that performs a window.open method to browse to a new site, you receive an &quot;unspecified error&quot; error message.
 * If you right-click a link and then click Open in New Window, it does not navigate at all.

Symptoms in Internet Explorer 5
NewWindow works as expected in Internet Explorer 5 when you click a link that performs a window.open method to browse to a new site, or when you right-click a link and then click Open in New Window.

However, when you use NewWindow2 in Internet Explorer 5, you may encounter the following problems:
 * If you click a link that performs a window.open method to browse to a new site, it does not navigate at all.
 * If you right-click a link and then click Open in New Window, you receive an &quot;unspecified error&quot; error message.

Symptoms in Internet Explorer 4.x
NewWindow works as expected in Internet Explorer 4.x when you click a link that performs a window.open method to browse to a new site, or when you right-click a link and then click Open in New Window.

However, when you use NewWindow2 in Internet Explorer 4.x, you may encounter the following problems:
 * If click a link that performs a window.open method to browse to a new site, it does not navigate.
 * If you right-click a link and then click Open in New Window, you receive an &quot;unspecified error&quot; error message.



RESOLUTION
To work around this problem, open the link in a new window within your application instead of opening it in the same window. For additional information, click the article number below to view the article in the Microsoft Knowledge Base:

184876 HOWTO: Use the WebBrowser Control NewWindow2 Event

Note that the NewWindow event works in Internet Explorer 4.x and Internet Explorer 5. Thus, if you only have to support those versions of the browser, you can use the NewWindow event.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce Behavior
If you have a Microsoft Foundation Classes (MFC) application and use NewWindow to navigate in the same window, the following code fails in Internet Explorer 5.5: void CDWebBrowserEvents::OnNewWindow(BSTR URL, long Flags, BSTR TargetFrameName,                 VARIANT* PostData, BSTR Headers, BOOL FAR* Processed) {   if (m_Browser) { COleVariant varEmpty; *Processed = TRUE; m_Browser->Navigate((LPCSTR)URL, &varEmpty, &varEmpty, &varEmpty, &varEmpty); } }

If you use NewWindow2, the following code fails in all versions of the Internet Explorer: void CIEDlg::OnNewWindow2(LPDISPATCH FAR* ppDisp, BOOL FAR* Cancel) {

IUnknown* pUnk = m_Browser.GetControlUnknown; if (pUnk) {       IDispatch* pDisp = NULL; HRESULT hr = pUnk->QueryInterface(IID_IDispatch, (void**)&pDisp);

if (SUCCEEDED(hr) && pDisp) *ppDisp = pDisp; } }

