prevent opening popup in internet explorer

A common problem while using webBrowser control is open pop up windows in instance of Internet Explorer and not in your application.
There’s a simple way to prevent this.

Logic is to capture the event when New Window is opened | Grab Link | Open it programatically in our application | cancel opening IE.

and code would be :

    Private Sub WebBrowser1_NewWindow(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles WebBrowser1.NewWindow
        ' This will be triggered only when link tries to open in new window.
        ' That means active element in web document will always be a Link.

        Dim myElement As HtmlElement = WebBrowser1.Document.ActiveElement
        Dim target As String = myElement.GetAttribute("href")

        Dim newInstance As New Form1

        'cancel opening IE window
        e.Cancel = True
    End Sub

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s