A WebBrowser control application opens a blank page in a new Internet Explorer window (839566)



The information in this article applies to:

  • Microsoft Internet Explorer (Programming) 6.0

SYMPTOMS

Consider the following scenario:
  • You create a WebBrowser control application that sinks the NewWindow2 event.
  • You try to open a link on a Web page in a new Microsoft Internet Explorer window.
In this scenario, the WebBrowser control application opens a blank page in the new window.

CAUSE

The issue occurs when the WebBrowser control application also sinks the BeforeNavigate2 event to add custom headers and reopen the Web page. Opening the Web page in the new window fails because a design limitation exists in Microsoft Internet Explorer.

WORKAROUND

To work around this issue, do not use the BeforeNavigate2 event to add custom headers. Instead, use another method. For example, use the OnAmbientPropertyChange event to add the custom header to the UserAgent string. Then, raise this event by using the DISPID_AMBIENT_USERAGENT parameter in the BeforeNavigate2 event.
STDMETHODIMP CAtlCompCtrl::OnAmbientPropertyChange(DISPID dispid)
{
	char tempbuf[MAX_PATH];
	char szUA[MAX_PATH];
	DWORD nUAStrLen = sizeof(szUA)/sizeof(szUA[0]) - 1;

    if(::ObtainUserAgentString (0, szUA, &nUAStrLen) != S_OK) return FALSE;

    // Only add our piece to the user agent if it is not there already.
    if (strstr(szUA, MY_UAS) == 0)
    {
       
        char* wptr;
        int pos;
        wptr = strstr(szUA,"; Windows");

        if (wptr)
        {
            pos = wptr - szUA;
            strncpy(tempbuf, szUA, pos);
            tempbuf[pos] = 0;
            strcat(tempbuf, MY_UAS);
            strcat(tempbuf, wptr);
            ::UrlMkSetSessionOption(URLMON_OPTION_USERAGENT,
                                    tempbuf,
                                    ::strlen(tempbuf), 0);
        
        }
    }
	return 1;
}

REFERENCES

For more information, click the following article number to view the article in the Microsoft Knowledge Base:

183412 WebBrowser control clients share global settings

For more information about the OnAmbientPropertyChange event, visit the following Microsoft Developer Network (MSDN) Web site:

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.

MORE INFORMATION

The BeforeNavigate2 event is an Internet Explorer event sink function that you can use to cause an event to be triggered before navigation occurs in the Web browser. This event is triggered any time an action is performed that causes navigation to occur.

For more information about how to use the WebBrowser control NewWindow2 in Internet Explorer 5, click the following article number to view the article in the Microsoft Knowledge Base:

184876 How to use the WebBrowser control NewWindow2 event


Modification Type:MinorLast Reviewed:7/25/2006
Keywords:kbprb kbQFE kbIE600sp2fix kbIE600preSP2fix kbfix kbbug kbpubtypekc KB839566 kbAudDeveloper kbAudITPRO