I Have A Web Browser Project Made In .NET Using The Browser Control In The
Visual Studio Express Edition
But When I Click On A Link In The Browser Control It Opens Internet Explorer,
Could Any One Tell Me How To Intercept Those Events So I Can Open The Link
With A New Form

Dani AI

Generated

— links that open Internet Explorer are coming from the page asking for a new window (target="_blank" or JavaScript window.open). The WinForms WebBrowser raises a NewWindow event for those. 's comment about link markup is about changing the page, but to intercept clicks inside your app you need to handle the control events instead.

A simple, reliable approach: attach a click handler to all anchors after DocumentCompleted, cancel the default action and open your own Form with a WebBrowser that navigates to the anchor's href.

Private Sub WebBrowser1_DocumentCompleted(...) Handles WebBrowser1.DocumentCompleted
    For Each a As HtmlElement In WebBrowser1.Document.GetElementsByTagName("a")
        AddHandler a.Click, AddressOf Anchor_Click
    Next
End Sub

Private Sub Anchor_Click(sender As Object, e As HtmlElementEventArgs)
    Dim url = CType(sender, HtmlElement).GetAttribute("href")
    If url <> "" Then
        Dim f As New Form
        Dim wb As New WebBrowser With {.Dock = DockStyle.Fill}
        f.Controls.Add(wb)
        wb.Navigate(url)
        f.Show()
        e.ReturnValue = False
    End If
End Sub

If the page uses window.open or NewWindow is raised, handle WebBrowser.NewWindow, cancel it and try to read the target from Document.ActiveElement.GetAttribute("href"); note that ActiveElement may not always contain the URL for JS popups. See the NewWindow event and HtmlElement.GetAttribute docs for details (WebBrowser.NewWindow, HtmlElement.GetAttribute).

For full control over JS-created windows, override window.open in the page and call back into the host via ObjectForScripting (mark the host class ComVisible and set webBrowser.ObjectForScripting = Me) so JavaScript can pass the URL to your VB method. See WebBrowser.ObjectForScripting.

Troubleshooting: attach handlers in DocumentCompleted, watch for frames/cross-domain pages, and remember some pages use scripts that make URL extraction harder — in those cases injecting a small override for window.open is the most robust solution.

just write has follows:
< a href="pagename.aspx" ></a>
instead of opening the internet explorer....

How Do i Use That Piece Of Code.
I`Need More Info

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.