vb.net WebBrowser links to Default Web Browser

喜夏-厌秋 提交于 2019-12-25 08:28:11

问题


is there a way to detect a person clicking a link inside WebBrowser1, and then i can do

Process.Start(TheURL)

And then return the action as false so it doesn't click the link in the webbrowser object and just the process.


回答1:


Here ya go:

private void WebBrowser_Navigating(object sender, WebBrowserNavigatingEventArgs e)
  {  
        e.Cancel = true; // Cancel the event to avoid default behavior
        System.Diagnostics.Process.Start(e.Url.ToString()); // Open the link in the default browser
  }

EDIT: Meh, I had a few minutes. Here ya go again:

Private Sub WebBrowser1_Navigating(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs) Handles WebBrowser1.Navigating
  e.Cancel = True 'Cancel the event to avoid default behavior
  System.Diagnostics.Process.Start(e.Url.ToString()) 'Open the link in the default browser
End Sub


来源:https://stackoverflow.com/questions/5253409/vb-net-webbrowser-links-to-default-web-browser

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