locked
Querying current url and checking to see if on right page

    Question

  • How can I check if the webbrowser url is either:

    www.example1.com

    or

    www.example2.com

    and close the form if they are not on either.

    But, how how do I make it so that they can be on the url:

    www.example1.com/something or www.example1.com/etc without having to code in every single possible string of letters in the galaxy.

    Thank you for your help,

    Sam
    Thursday, August 07, 2008 4:36 PM

Answers

  • Hi Sam,

    I am not sure that I understood your scenario. If you need to check the
    URL of the current document, you can poll WebBrowser.Url property after you ensure that the WebBrowser.Isbusy is false. You also can handle the Navigating event to cancel navigation if certain conditions have not been met similar the following code snippet. If you have any further issues, feel free to tell us.

    Public Class Form1

        Private Sub WebBrowser1_Navigating(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs) Handles WebBrowser1.Navigating

            If (Not e.Url.ToString.Contains("www.microsoft.com")) Then

                e.Cancel = True

            End If

        End Sub

     

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

            WebBrowser1.Navigate("www.sina.com.cn")

        End Sub

    End Class


    Best regards,
    Riquel
    Monday, August 11, 2008 1:12 PM