Results 1 to 3 of 3

Thread: Any way to say search with random words like googel.com searches in google WEBbROWSER

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2014
    Posts
    33

    Any way to say search with random words like googel.com searches in google WEBbROWSER

    ok that made no sense in my question but i will explain it here(a web browser is what im making): lets say i wanted to go to youtube.com and i accidentally typed yuotube.com is there any way i can tell the browser that i want it to search with google if its not an actual valid url?

  2. #2
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: Any way to say search with random words like googel.com searches in google WEBbRO

    All you are doing is using the Internet explorer component. So you are not actually making a browser. These entrys are defined by your own internet explorer. To change these you will need to write to the registry.

  3. #3
    Member Aggierich's Avatar
    Join Date
    Oct 2011
    Posts
    32

    Re: Any way to say search with random words like googel.com searches in google WEBbRO

    Hello Austen,
    The problem here is that even though yuotube.com is not what you meant, someone may have this domain now or in the future as a quick way to get hits off people who actually meant to go to youtube. That said, you can make a request to the url to see if it is real, and compare it to the html code on a "cannot connect" page to reroute the browser to search google, but this gets more complicated then it is. I would suggest using regex to search patterns of the text in the textbox.

    For example:
    Code:
    Imports System.Net
    Imports System.Text.RegularExpressions
    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            ' check to see if textbox1.text has http or https and ends with a .com,.net,or .org etc etc..
            Dim pattern As String
            pattern = "http(s)?://([\w+?\.\w+])+([a-zA-Z0-9\~\!\@\#\$\%\^\&\*\(\)_\-\=\+\\\/\?\.\:\;\'\,]*)?"
    
            ' check to see if textbox1.text is good url just missing http or https
            Dim patterntwo As String
            patterntwo = "([\w+?\.\w+])+([a-zA-Z0-9\~\!\@\#\$\%\^\&\*\(\)_\-\=\+\\\/\?\.\:\;\'\,]*)?"
    
            'simple if, then for different cases
            If Regex.IsMatch(TextBox1.Text, pattern) Then
                WebBrowser1.Navigate(TextBox1.Text)
            ElseIf Regex.IsMatch(TextBox1.Text, patterntwo) Then
                If Regex.IsMatch(TextBox1.Text, "www") Then
                    WebBrowser1.Navigate("http://" + TextBox1.Text)
                Else : WebBrowser1.Navigate("http://www.google.com/search?q=" + TextBox1.Text)
                End If
            End If
    
        End Sub
    End Class
    This checks for 3 cases: If url is entire, if url is missing a part, or if just a statement was entered.
    Only downside to this is that if you type http://www.gloogle.com, is sees this as a correct pattern for a url,(aka it has "http://" & it has ".com" ending) so it will try to connect.
    You can always add a webrequest as a check to see if a url is valid before navigating, and if its not, set webbrowser1 to navigate to "http://www.google.com/search?q=" + textbox1.text instead.
    Others may have some better ways, but this is simple. Best of luck
    Last edited by Aggierich; Feb 14th, 2015 at 08:04 AM. Reason: Added case for url as keyword search

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width