Microsoft Knowledge Base Email Alertz

KBAlertz.com: (185538) - When hosting the Internet Explorer 4.x or later WebBrowser control in a Visual Basic application, you may want to have the navigation always occur in your application and not other Internet Explorer windows. If you handle the NewWindow2 event and set...

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 2.0 Web Hosting with SQL 2005: Click Here!
Discount ASP.NET Hosting


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




How To Cause Navigation to Occur in Same WebBrowser Window

Article ID:185538
Last Review:June 29, 2004
Revision:2.1
This article was previously published under Q185538

SUMMARY

When hosting the Internet Explorer 4.x or later WebBrowser control in a Visual Basic application, you may want to have the navigation always occur in your application and not other Internet Explorer windows. If you handle the NewWindow2 event and set the Cancel flag equal to True, navigation is canceled completely. Since NewWindow2 does not provide you with the URL to navigate to as the Internet Explorer 3.x NewWindow event did, there doesn't appear to be any way to have the navigation occur in the same window.

Fortunately, Internet Explorer 4.x or later provide the WebBrowser_V1 object for compatibility with Internet Explorer 3.x. Using the WebBrowser_V1 object, you can have your application receive events from version 3.x, 4.x, and 5.x. That means that you can handle the version 3.x NewWindow event and then have the navigation occur in the current window.

Back to the top

MORE INFORMATION

In order to implement this functionality in your Visual Basic application, follow these step:
1.Create a form with a WebBrowser control on it.
2.In the declarations section of that form, add the following:
      Dim WithEvents Web_V1 as SHDocVwCtl.WebBrowser_V1
						
This will declare a WebBrowser_V1 variable that can receive events WebBrowser_V1 provides you with the NewWindow event.
3.In the Form_Load event, add the following:
      Set Web_V1 = WebBrowser1.Object
	  WebBrowser1.Navigate2 "http://www.microsoft.com"
						
This sets the WebBrowser_V1 object to the existing Internet Explorer WebBrowser object.
4.After the NewWindow2 event fires, the Web_V1_NewWindow event will fire with the linked URL as one of its input arguments. Remember not to set Cancel to True in NewWindow2. Also, set the Processed variable to True in the NewWindow event handler so that a new instance of Internet Explorer will not be created. The following code shows this event handler and the code necessary to navigate within the current window:
      Private Sub Web_V1_NewWindow(ByVal URL As String, _
                                   ByVal Flags As Long, _
                                   ByVal TargetFrameName As String, _
                                   PostData As Variant, _
                                   ByVal Headers As String, _
                                   Processed As Boolean)
         Processed = True
         WebBrowser1.Navigate URL
      End Sub
					
5.Right-click a link and select "Open in New Window" and you will find the link will still open inside your WebBrowser Control.

Please note that Internet Explorer does not fire a NewWindow or NewWindow2 event when the user presses CTRL+N or points to New under the File menu and clicks Window.

Back to the top

REFERENCES

For additional information, please see the following article in the Microsoft Knowledge Base:
184876 (http://kbalertz.com/Feedback.aspx?kbNumber=184876/EN-US/) How To Use the WebBrowser Control NewWindow2 Event
For more information, see the MSDN Online Web Workshop:
http://msdn.microsoft.com/workshop/ (http://msdn.microsoft.com/workshop/)
(c) Microsoft Corporation 1998, All Rights Reserved. Contributions by Scott Roberts, Microsoft Corporation

Back to the top


APPLIES TO
Microsoft Internet Explorer 4.0 128-Bit Edition
Microsoft Internet Explorer 4.01 Service Pack 2
Microsoft Internet Explorer 5.0
Microsoft Internet Explorer 5.5

Back to the top

Keywords: 
kbhowto kbwebbrowser KB185538

Back to the top

       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

jeff - jeff NOSPAM-AT-NOSPAM federated.com Reported as Irrelevant  
Written: 8/22/2005 8:43 AM
I was excited when I came across the above article since I am trying to use the NewWindow3 event within VB6 (SP6) but the "NewWindow" event using the approach above does not fire (I'm guessing because I have I.E. 6.x; the article says it applies up to I.E. 5.5). I would really like to use the "NewWindow3" event but it appears that the "dwFlags" argument within the interface is not compatible with VB 6: Here is what the VB6 Object Browser displays: Event NewWindow3(ppDisp As Object, Cancel As Boolean, dwFlags As <Unsupported variant type>, bstrUrlContext As String, bstrUrl As String) Member of SHDocVwCtl.WebBrowser A new, hidden, non-navigated WebBrowser window is needed. Does anyone know of a work around to allow me to get access to the URL within the "NewWindow2" event which appears to be the only one that I receive? Jeff Althof

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please