Search code examples
javascripttextinputgoogle-search

use google to search in a url


I want to use Google to search in my URL. I want to use these code:

site: http://my-url.ir/ my_words_that_want_to_search

then I have a text input and a button for search

I want HTML(or JavaScript) that when I click on the button put text that is in text input in

site: http://my-url.ir/ text_that_is_in_text_input

Solution

  • Check out the Google Custom Search Engine, which will create such code snippets for you.

    According to this query string anatomy, you can just add another parameter instead of adding site:xyz to the search string:

    <form method="GET" action="//www.google.de/search">
        <input type="hidden" name="as_sitesearch" value="http://example.com">
        <input type="text" name="q">
        <input type="submit" value="Search!">
    </form>
    

    No need to use JavaScript for a simple search form.