user1970090
user1970090

Reputation: 235

Webbrowser current URL (VB.NET)

Im working on a project , and i have an obstacle about webbrowser tool in vb.net . I want to show a msgbox when the user is in a specific site , how can this be done ? , in another words , how can i get the current url in the webberowser tool in vb.net?

Upvotes: 1

Views: 32720

Answers (3)

Gerrit
Gerrit

Reputation: 1

Is this what you mean?

Dim browser As String


    browser = TextBox1.Text
    WebBrowser1.Navigate(browser)

    MsgBox("Your visiting " & browser)

End Sub

Upvotes: -1

John Koerner
John Koerner

Reputation: 38077

I would say you should check the Host of the URI, that way it works for all of the URLs and not just the top level for a given site:

Private Sub Button1_Click_1( sender As System.Object,  e As System.EventArgs) Handles Button1.Click
       WebBrowser1.Navigate("http://www.stackoverflow.com")
End Sub

Private Sub WebBrowser1_DocumentCompleted( sender As System.Object,  e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
    If WebBrowser1.Url.Host = "stackoverflow.com"
        MessageBox.Show("You are at stack overflow")
    End If
End Sub

Upvotes: 2

GSerg
GSerg

Reputation: 78190

Webbrowser.Url is a Uri, not a string. So compare it with a Uri.

If WebBrowser1.Url = New Uri("http://stackoverflow.com") Then

Upvotes: 2

Related Questions