Microsoft KB Archive/839566

= A WebBrowser control application opens a blank page in a new Internet Explorer window =

Article ID: 839566

Article Last Modified on 5/21/2007

-

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,&quot;; Windows&quot;);

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



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the &quot;Applies to&quot; 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

Keywords: kbprb kbqfe kbie600sp2fix kbie600presp2fix kbfix kbbug kbpubtypekc KB839566

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.