网络浏览器当前 URL (VB.NET)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14279094/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 16:33:47  来源:igfitidea点击:

Webbrowser current URL (VB.NET)

vb.net

提问by user1970090

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?

我在做一个项目,我在 vb.net 中遇到了关于 webbrowser 工具的障碍。当用户在特定站点时,我想显示一个 msgbox,如何做到这一点?,换句话说,如何在 vb.net 的 webberowser 工具中获取当前 url?

回答by GSerg

Webbrowser.Urlis a Uri, not a string. So compare it with a Uri.

Webbrowser.Url是一个Uri,而不是一个字符串。因此,将其与Uri.

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

回答by John Koerner

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:

我会说你应该检查 URI 的主机,这样它适用于所有 URL,而不仅仅是给定站点的顶级:

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

回答by Gerrit

Is this what you mean?

你是这个意思吗?

Dim browser As String


    browser = TextBox1.Text
    WebBrowser1.Navigate(browser)

    MsgBox("Your visiting " & browser)

End Sub