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



The information in this article applies to:

  • Microsoft Internet Explorer (Programming) 4.0
  • Microsoft Internet Explorer (Programming) 4.01
  • Microsoft Internet Explorer (Programming) 4.01 SP1
  • Microsoft Internet Explorer (Programming) 4.01 SP2
  • Microsoft Internet Explorer (Programming) 5
  • Microsoft Internet Explorer (Programming) 5.01
  • Microsoft Internet Explorer (Programming) 5.01 SP1
  • Microsoft Internet Explorer (Programming) 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 "unspecified error" 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 "unspecified error" 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 "unspecified error" 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.

MORE INFORMATION

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;
	}
}
				

REFERENCES

For additional information, click the article numbers below to view the articles in the Microsoft Knowledge Base:

185538 HOWTO: Cause Navigation to Occur in Same WebBrowser Window

184876 HOWTO: Use the WebBrowser Control NewWindow2 Event

194242 FIX: window.open Causes Delay in NewWindow Event

For more information about reusing browser technology, see the following Microsoft Web site: For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:

Modification Type:MajorLast Reviewed:5/11/2006
Keywords:kbBug kbnofix kbWebBrowser KB294870