Change target of links in WebBrowser control

你。 提交于 2019-12-24 18:06:10

问题


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?


回答1:


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)




回答2:


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



来源:https://stackoverflow.com/questions/8379598/change-target-of-links-in-webbrowser-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!