Open a webpage in the default browser

后端 未结 8 1643
我寻月下人不归
我寻月下人不归 2020-12-03 20:39

I want my users to be able to click a button to open my company\'s webpage in the default browser when clicked. How would I do this?

I\'m using VB.net so all .net e

相关标签:
8条回答
  • 2020-12-03 21:10

    Here is a little sub that may just interest some people who need to specify the browser. (but its not as good as a 12" pizza sub!) :P

    Private Sub NavigateWebURL(ByVal URL As String, Optional browser As String = "default")
    
        If Not (browser = "default") Then
            Try
                '// try set browser if there was an error (browser not installed)
                Process.Start(browser, URL)
            Catch ex As Exception
                '// use default browser
                Process.Start(URL)
            End Try
    
        Else
            '// use default browser
            Process.Start(URL)
    
        End If
    
    End Sub
    

    Call: will open www.google.com in Firefox if it is installed on that PC.

    NavigateWebURL("http://www.google.com", "Firefox") '// safari Firefox chrome etc
    

    Call: will open www.google.com in default browser.

    NavigateWebURL("http://www.google.com", "default")
    

    OR

    NavigateWebURL("http://www.google.com")
    
    0 讨论(0)
  • 2020-12-03 21:10

    This worked perfectly for me. Since this is for personal use, I used Firefox as my browser.

     Dim url As String
        url = "http://www.google.com"
        Process.Start("Firefox", url)
    
    0 讨论(0)
  • 2020-12-03 21:17

    This should work:

    Dim webAddress As String = "http://www.example.com/"
    Process.Start(webAddress)
    
    0 讨论(0)
  • 2020-12-03 21:25

    System.Diagnostics.Process.Start("http://www.example.com")

    0 讨论(0)
  • 2020-12-03 21:28
    Dim URL As String 
    Dim browser As String = TextBox1.Text
    URL = TextBox1.Text
    Try
        If Not (browser = TextBox1.Text) Then
            Try
                Process.Start(browser, URL)
            Catch ex As Exception
                Process.Start(URL)
            End Try
        Else
            Process.Start(URL)
        End If
    
    Catch ex As Exception
        MsgBox("There's something wrong!")
    End Try
    
    0 讨论(0)
  • 2020-12-03 21:31

    You can use Process.Start:

    Dim url As String = “http://www.example.com“
    
    Process.Start(url)
    

    This should open whichever browser is set as default on the system.

    0 讨论(0)
提交回复
热议问题