Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

This article was previously published under Q294870

↑ Back to the top


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.

↑ Back to the top


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.

↑ Back to the top


Status

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

↑ Back to the top


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

↑ Back to the top


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:

↑ Back to the top


Keywords: kbbug, kbnofix, kbwebbrowser, KB294870

↑ Back to the top

Article Info
Article ID : 294870
Revision : 3
Created on : 5/11/2006
Published on : 5/11/2006
Exists online : False
Views : 354