Passing html form values to google search query

后端 未结 2 496
野性不改
野性不改 2021-01-28 05:40

SIDENOTE: Before everyone tells me about google\'s custom search engine, I have been using that until now but i find it really hard to style that search box and it broke on my

相关标签:
2条回答
  • 2021-01-28 06:28

    I have found another thread that was asking exactly what i wanted here: Add Google search in web page

    Here is the code snippet for the lazy:

    You just need to set the form method to "get", add one extra hidden element with the site you want to search and it will automatically paste it behind the URL as such:

    <form action="https://google.com/search" method="get">
        <input type="hidden" name="sitesearch" value="http://acme.com" />
        <input type="text" name="q" />
    </form>
    

    Because that is how HTML forms work by default

    0 讨论(0)
  • 2021-01-28 06:34

    What about such construction:

    <form role="search" method="get" action="https://www.google.com/search?q=site:reddit.com+x">
        <div class="search-control">
            <input type="search" id="site-search" name="x"
                   placeholder="Search the site..."
                   aria-label="Search through site content">
            <button>Search</button>
        </div>
    </form>
    
    0 讨论(0)
提交回复
热议问题