locked
My Web Browser RRS feed

  • Question

  • When i click the link inside my webpage of my visual basic 2008 web browser, it will open a new window of my visual basic 2008 web browser rather than opening internet explorer. How can i do that? Please help me... I'm still learning visual basic.

    Sunday, January 25, 2009 12:15 PM

Answers

  • You need to handle DWebBrowserEvents2.NewWindow3 event. We can cast the WebBrowser.ActiveXInstance to a SHDocVx.WebBrowser object, then we can add the NavigateError and NewWindow3 event handlers to handle these event. However, you have to add reference to the Microsoft Internet Control in the COM tab on the Add Reference dialog. Here is the code snippet about how to handle the NavigateError event. Actually .net 2.0 webbrowser control is a wrapper of the underlying internet control. It is a com object. Here we can add event handler to the COM object event to implement this. You can use this method to create a multitab webbrowser when a new window is created.

    Imports SHDocVw

    Public Class Form2

    Public Sub New()

    Me.InitializeComponent()

    Me.WebBrowser1.Navigate("http://www.yahoo.com")

    Dim svd As SHDocVw.WebBrowser = DirectCast(Me.WebBrowser1.ActiveXInstance, SHDocVw.WebBrowser)

    AddHandler svd.NavigateError, AddressOf Svd_NavigateError

    AddHandler svd.NewWindow3, AddressOf NewWindow3

    End Sub

    Sub Svd_NavigateError(ByVal pDisp As Object, ByRef URL As Object, ByRef Frame As Object, ByRef StatusCode As Object, ByRef Cance As Boolean)

    MessageBox.Show("error")

    End Sub

    Public Sub NewWindow3(ByRef pDisp As Object, ByRef cancel As Boolean, ByVal flags As Integer, _

    ByVal URLContext As String, ByVal URL As String)

    WebBrowser1.Navigate(URL)

    cancel = True

    End Sub

    End Class

     

    About the DWebBrowserEvents2::NewWindow3 event, visit http://msdn2.microsoft.com/en-us/library/aa768288(VS.85).aspx. If you have any further questions, please tell me.


    You also can read the following articles about how to extend the current webbrowser control.

    1. Working with the Web Browser Control in Visual Studio 2005 - IE7Clone. This article and accompanying sample application is to show working with the new WebBrowser Control in Visual Studio 2005 by cloneing many of the features in Internet Explorer 7. It is a good example about extending the webbrowser control.

    2. Extended .NET 2.0 WebBrowser Control. This article explains how to extend the WebBrowser control and add functionality for things like pop-up blocking, script error handling, and handling new windows in a tabbed browser environment.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Wednesday, January 28, 2009 10:35 AM
    Moderator

All replies

  • I think what you mean is when you click a link inside your vb webbrowser it will open a new internet explorer window.  If this is not the case, and the case is actually when you click a link in your web browser control it opens a new instance of your vb program, you have more going on then your telling us.  Provide the complete source code for your situation.
    Compensating what I don't know yet, with what I do know now.
    Monday, January 26, 2009 10:49 AM
  •  
    Yes, when you click a link inside your vb webbrowser it will open a new internet explorer window. Instead of opening in internet explorer, I want it to open in my visual basic web browser (WebBrowser1).
    Monday, January 26, 2009 12:12 PM
  • Consider this :

    Public Class Form1  
     
        Private Sub Form1_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load  
            Dim myWebBrowser As New WebBrowser  
            myWebBrowser.Dock = DockStyle.Fill  
            myWebBrowser.Navigate("www.yahoo.com")  
     
            Me.Controls.Add(myWebBrowser)  
        End Sub 
    End Class 

     

    If I click on a link in yahoo, it navigates to the new link within the same myWebBrowser object.  What happens if YOU run the same code above and click on one of the links?


    Compensating what I don't know yet, with what I do know now.
    Monday, January 26, 2009 1:05 PM
  • You need to handle DWebBrowserEvents2.NewWindow3 event. We can cast the WebBrowser.ActiveXInstance to a SHDocVx.WebBrowser object, then we can add the NavigateError and NewWindow3 event handlers to handle these event. However, you have to add reference to the Microsoft Internet Control in the COM tab on the Add Reference dialog. Here is the code snippet about how to handle the NavigateError event. Actually .net 2.0 webbrowser control is a wrapper of the underlying internet control. It is a com object. Here we can add event handler to the COM object event to implement this. You can use this method to create a multitab webbrowser when a new window is created.

    Imports SHDocVw

    Public Class Form2

    Public Sub New()

    Me.InitializeComponent()

    Me.WebBrowser1.Navigate("http://www.yahoo.com")

    Dim svd As SHDocVw.WebBrowser = DirectCast(Me.WebBrowser1.ActiveXInstance, SHDocVw.WebBrowser)

    AddHandler svd.NavigateError, AddressOf Svd_NavigateError

    AddHandler svd.NewWindow3, AddressOf NewWindow3

    End Sub

    Sub Svd_NavigateError(ByVal pDisp As Object, ByRef URL As Object, ByRef Frame As Object, ByRef StatusCode As Object, ByRef Cance As Boolean)

    MessageBox.Show("error")

    End Sub

    Public Sub NewWindow3(ByRef pDisp As Object, ByRef cancel As Boolean, ByVal flags As Integer, _

    ByVal URLContext As String, ByVal URL As String)

    WebBrowser1.Navigate(URL)

    cancel = True

    End Sub

    End Class

     

    About the DWebBrowserEvents2::NewWindow3 event, visit http://msdn2.microsoft.com/en-us/library/aa768288(VS.85).aspx. If you have any further questions, please tell me.


    You also can read the following articles about how to extend the current webbrowser control.

    1. Working with the Web Browser Control in Visual Studio 2005 - IE7Clone. This article and accompanying sample application is to show working with the new WebBrowser Control in Visual Studio 2005 by cloneing many of the features in Internet Explorer 7. It is a good example about extending the webbrowser control.

    2. Extended .NET 2.0 WebBrowser Control. This article explains how to extend the WebBrowser control and add functionality for things like pop-up blocking, script error handling, and handling new windows in a tabbed browser environment.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Wednesday, January 28, 2009 10:35 AM
    Moderator