Simon Canning
Simon Canning

Reputation: 215

Change target of links in WebBrowser control

Sometimes when I click on a link, it opens in a new window. Can I prevent this from happening and just load the page in my current window?

Upvotes: 1

Views: 2080

Answers (2)

Jon B
Jon B

Reputation: 362

This is working for me (so far):

Private Sub browser_NewWindow(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles browser.NewWindow
    e.Cancel = True
    browser.Navigate(browser.StatusText)
End Sub

Really simple, if the status text is the url (which it always is for the documents I am browsing)

Upvotes: 3

Sheng Jiang 蒋晟
Sheng Jiang 蒋晟

Reputation: 15281

If you are targeting Windows XP SP2 or later, you can catch the NewWindow3 event to get the target url, and after setting the cancel parameter, navigate to the url instead.

For earlier versions of IE you can catch the obsolete NewWindow event with the same handling as documented in Q185538 How To Cause Navigation to Occur in Same WebBrowser Window

Upvotes: 0

Related Questions